dev-master 2020-05-18 10:43 UTC

This package is auto-updated.

Last update: 2024-04-18 19:31:24 UTC


Build Status Code Coverage Scrutinizer Code Quality Code Intelligence Status


  • PSR-11 full featured implementation.
  • Allows autowire via file finder and/or configuration file.
  • Allows delegate lookup and resolve dependencies from other containers.
  • Allows scalar types injection via parameters bag.
  • Detects circular references.
  • Supports aliasing.
  • Supports closures.
  • Supports PSR-16 cache.

Using container

Container can be initialized with file finder.

// autowire all classes in Samples directory
$fileFinder = (new \Borodulin\Finder\ClassFinder())
// build container
$container = (new \Borodulin\Container\ContainerBuilder())

Container can be initialized via configuration file.


return [
    '' => Bar::class,
    '' => function (Bar $bar) {
        return new Foo($bar);
// build container
$container = (new \Borodulin\Container\ContainerBuilder())
    ->setConfig(require(__DIR__ . '/config/definitions.php'))

After the container is built, objects can be obtained via get():

$object = $container->get('');

But it is not recommended.

“users SHOULD NOT pass a container into an object, so the object can retrieve its own dependencies. Users doing so are using the container as a Service Locator. Service Locator usage is generally discouraged.”

Using aliases

Using closures

Using parameters bag

Delegate lookup

Using cache