Skip to content

webstream-framework/DI

Repository files navigation

DI

build Scrutinizer Code Quality Code Coverage

This Library is module for dependency injection.

Usage

Using Injector#inject:

class Sample
{
    use Injector;

    public function getValue()
    {
        return $this->value;
    }
}

$obj = new Sample();
$obj->inject('value', 'test');
echo $obj->getValue(); // test

You can even set the undefined property value if using the Injector#inject method.

Using Injector#strictInject:

class SampleValue {}

class Sample
{
    use Injector;

    /**
     * @var SampleValue
     */
    private $value;

    public function getValue()
    {
        return $this->value;
    }
}

$obj = new Sample();
$obj->strictInject('value', new SampleValue());
echo $obj->getValue(); // Return value is instance of SampleValue class.

Thrown AnnotationException exception when specified the difference value type.
However, the primitive values (int, string, bool etc.) can not be strict value inject.

License

Licensed under the MIT http://www.opensource.org/licenses/mit-license.php

About

Dependency injection modules.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published