Skip to content
PSR-11 compatible injector
Branch: master
Clone or download
Latest commit 5e771c1 Jul 8, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Update templates and configs from template Jun 28, 2019
src Cleanup Jul 7, 2019
tests Fix tests Jul 7, 2019
.gitattributes Initial commit Jun 14, 2019
.gitignore Initial commit Jun 14, 2019
.scrutinizer.yml Update templates and configs from template Jun 28, 2019
.styleci.yml Initial commit Jun 14, 2019
.travis.yml Initial commit Jun 14, 2019
CHANGELOG.md Added injector code Jun 14, 2019
LICENSE.md Initial commit Jun 14, 2019
README.md
composer.json Add factory dependency Jul 1, 2019
phpunit.xml.dist

README.md

Yii Injector


The package is PSR-11 compatible injector that is able to invoke methods resolving their dependencies via autowiring.

Latest Stable Version Total Downloads Build Status Scrutinizer Code Quality

General usage

$container = new Container([
    EngineInterface::class => EngineMarkTwo::class,
]);

$getEngineName = function (EngineInterface $engine) {
    return $engine->getName();
};

$injector = new Injector($container);
echo $injector->invoke($getEngineName);
// outputs "Mark Two"

In the code above we feed out container to Injector when creating it. Any PSR-11 container could be used. When invoke is called, injector reads method signature of the method invoked and, based on type hinting automatically obtains objects for corresponding interfaces from container.

You can’t perform that action at this time.