digitalwindow / dependency-injection
Easy-to-use Dependency Injection in PHP
1.0.7
2014-03-21 15:09 UTC
Requires
- php: >=5.3.3
Requires (Dev)
- phpunit/phpunit: 3.7.*
- symfony/class-loader: 2.4.*
This package is not auto-updated.
Last update: 2025-02-25 08:28:25 UTC
README
Dependency injection for PHP
Usage Examples
$injector = new \Awin\DependencyInjection\DependencyInjector;
$injector->configureDependencyParamValue('Foo', 'param1', 'value to use in constructor');
$injector->configureDependencyParamClass('Foo', 'param2', '\Bar');
$foo = $injector->get('Foo')';
Configuration-Free Usage
Simply type-hint the constructor parameters of your dependency, and you needn't offer any configuration information to the injector - it will use reflection to figure out what is needed.
E.g.:
class Foo
{
public function __construct(Bar $param)
{
//...
}
//...
}
$foo = $injector->get('Foo'); // Constructor param retrieved recursively from
// injector at this point, based on type-hint.