digitalwindow / 依赖注入
易于使用的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: 2024-09-24 06:21:29 UTC
README
PHP依赖注入
使用示例
$injector = new \Awin\DependencyInjection\DependencyInjector;
$injector->configureDependencyParamValue('Foo', 'param1', 'value to use in constructor');
$injector->configureDependencyParamClass('Foo', 'param2', '\Bar');
$foo = $injector->get('Foo')';
无需配置的使用
只需对依赖的构造函数参数进行类型提示,您无需向注入器提供任何配置信息 - 它将通过反射来确定需要什么。
例如:
class Foo
{
public function __construct(Bar $param)
{
//...
}
//...
}
$foo = $injector->get('Foo'); // Constructor param retrieved recursively from
// injector at this point, based on type-hint.