Skip to content


This is a very simple lightweight PSR-11 Container implementation.


composer require sonsofphp/container



use SonsOfPHP\Component\Container\Container;
use Psr\Container\ContainerInterface;

$container = new Container();
$container->set('', function (ContainerInterface $container) {
    return new Service();
$container->set('', function (ContainerInterface $container) {
    return new Service($container->get(''));

// Services will not be created until they are called, once called, they will
// always return the same instance of the service. That means that in the
// following code, the "" is only constructed once.
$service  = $container->get('');
$service2 = $container->get('');