1. Go to this page and download the library: Download castor/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/ */
use Psr\Container\ContainerInterface;
$container = Castor\Container::boot();
$container->register('foo', fn() => new Foo());
$container->inflect('foo', function (Foo $foo, ContainerInterface $container) {
$foo->setBar($container->get(Bar::class));
});
$foo = $container->get('foo');
use Psr\Container\ContainerInterface;
$container = Castor\Container::boot();
$container->register('foo', fn() => new Foo());
$container->inflect('foo', function (Foo $foo, ContainerInterface $container) {
return new FooBar($foo, $container->get(Bar::class));
});
$foo = $container->get('foo'); // instance of FooBar
$container = Castor\Container::boot();
// Foo will be instantiated using reflection when a service Foo is requested.
$container->register(Foo::class);
// Foo will be instantiated when a FooInterface service is requested.
$container->register(FooInterface::class, Foo::class);
$container = Castor\Container::boot();
// Foo will be automatically instantiated using reflection.
$container->get(Foo::class);
$container = Castor\Container::boot(4); // This flag only enables caching.