1. Go to this page and download the library: Download polymorphine/container library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
polymorphine / container example snippets
use Polymorphine\Container\Setup;
$setup = Setup::production();
$setup->set('value')->value('Hello world!');
$setup->set('domain')->value('http://api.example.com');
$setup->set('direct.object')->value(new ClassInstance());
$setup->set('deferred.object')->callback(function (ContainerInterface $c) {
return new DeferredClassInstance($c->get('value'));
});
$setup->set('composed.factory')->instance(ComposedClass::class, 'direct.object', 'deferred.object');
$setup->set('factory.product')->product('composed.factory', 'create', 'domain');
$container = $setup->container();
$container->has('composed.factory'); // true
$container->get('factory.product'); // return result of ComposedClass::create() call
$setup = Setup::production([
'value' => new Record\ValueRecord('Hello world!'),
'domain' => new Record\ValueRecord('http://api.example.com'),
'direct.object' => new Record\ValueRecord(new ClassInstance()),
'deferred.object' => new Record\CallbackRecord(function (ContainerInterface $c) {
return new DeferredClassInstance($c->get('env.value'));
}),
'composed.factory' => new Record\InstanceRecord(Factory::class, 'direct.object', 'deferred.object'),
'factory.product' => new Record\ProductRecord('composed.factory', 'create', 'domain')
]);
// add more entries here with set() methods
// and instantiate container...
$container = $setup->container();