PHPComponent/DI is Dependency Injection container
0.2.6
2017-10-15 19:02 UTC
Requires
- php: ~5.6
- php-component/atomic-file: ~0.1
- php-component/php-code-generator: ~0.1
Requires (Dev)
- phpunit/phpunit: ^5.7.5
This package is not auto-updated.
Last update: 2025-03-30 06:29:57 UTC
README
DI is Dependency Injection container. It will build whole dependency tree of your application.
Configuration example
You can configure container using PHP.
For example you have class Translator, which have one constructor parameter $default_language
.
class Translator { /** @var string */ private $default_language; public function __construct($default_language) { $this->default_language = $default_langauge; } }
Then you configure Container.
$parameters = new \PHPComponent\DI\ParametersBag(array('default_language' => 'en')); $container_builder = new \PHPComponent\DI\ContainerBuilder($parameters); $container_builder->registerService('translator', Translator::class) ->setArguments(array('%default_language%')); $translator = $container_builder->getService('translator');
When you call getService('translator')
you will get Translator with default language en.