张柏 burn/samburns / dirty-needle
PHP 的依赖注入容器
3.0.3
2015-03-15 17:50 UTC
Requires
- php: >= 5.4.0
Requires (Dev)
- behat/behat: 3.0.15
- henrikbjorn/phpspec-code-coverage: ~1.0.1
- phpspec/phpspec: 2.1.1
- phpunit/phpunit: ~4.5
- satooshi/php-coveralls: dev-master
README
dirty-needle
简介
PHP 的依赖注入容器
设置一个返回 PHP 数组的配置文件,例如
<?php return array( 'dirty-needle' => array( '@dependency' => array( 'class' => '\Dependency' ), '@class-with-dependency' => array( 'class' => '\ClassWithDependency', 'arguments' => array( '@dependency' ) ), ), );
然后从容器中获取东西,如下所示
$diContainer = \DirtyNeedle\DiContainer()::getInstance(); $diContainer->addConfigFile('/path/to/config.php'); $classWithDependency = $diContainer->get('class-with-dependency');
您还可以注入模拟对象
$diContainer->set('service-id', $mockObject);
重置定义和模拟
$diContainer->reset();
版本支持 PHP5.3-5.6,其中 5.6 兼容版本在实现上速度明显更快。
版本控制
本项目使用 语义版本控制。