dependency injection container

2.0.0 2019-10-07 14:14 UTC

README

Build Status Coveralls

Dependency injection container Martin Fowler's article

Dependency injection container — it is an object to instantiate the class and its dependent objects.

This is in accordance with the recommendations of PSR-11.

It supports the following kinds of dependency injection:

  • Constructor injection;
  • Property injection;
  • Setter injection

Example:

use suffi\di\Container;

$foo = new Foo();
$bar = new Bar();
$thy = new Thy();

$container->set('foo', $foo);
$container->set('bar', $bar);
$container->set('thy', $thy);

$container->setDefinition('common', 'Common')
    ->parameter('foo', 'foo')
    ->property('bar', $bar)
    ->setter('thy', 'thy');

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

Installation

composer require dmitry-suffi/di

Documentation

the documentation can be found here:

Tests

You can also browse the functional tests

License

Copyright (c) 2016-2016 Dmitry Suffi. Released under the MIT license.