$ composer require lucid/di:dev-develop
container-interop/container-interop
<?php
use Lucid\DI\Container;
$container->set('foo', new Acme\Foo);
$container->get('foo'); // instance of Acme\Foo
<?php
$container->setAlias('foo', 'bar');
$container->get('bar'); // instance of Acme\Foo
<?php
// throws `Interop\Container\Exception\ContainerException`
$container->set('foo', new Acme\Bar);
// use `replace` instead
$container->replace('foo', new Acme\Bar);
// or use `$forcereplace`
$container->set('foo', new Acme\Bar, Container::FORCE_REPLACE_ON_DUPLICATE);
<?php
use Lucid\DI\ContainerBuilder;
use Lucid\DI\Definition\Service;
$container = new ContainerBuilder;
// define a service by id and class
$service = $container->define('foo', 'Acme\Foo');
// You can configure the service in detail
$service->...
// basically the same
$container->setService('foo', $service = new Service('Acme\Foo'));