matico / simple-php-di
SimplePHPDI
dev-master
2019-03-15 16:48 UTC
Requires
- php: >=5.3.3
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is auto-updated.
Last update: 2024-09-16 04:57:13 UTC
README
为PHP(5.3.x ~)提供的简单依赖注入库
如何工作
- 注入注解
- @Inject 通常注入对象实例
/**
*
* @author matico
* @Inject Address
* @Inject Skill
*
*/
class Developer {
}
- @InjectSingleton 注入单例对象
/**
*
* @author matico
* @InjectSingleton Country
*/
class Address {
}
$maticoDeveloper = DI::get('Developer', array('name'=>'matico'));
$maticoInfo = $maticoDeveloper->info();
$congmtDeveloper = DI::get('Developer', array('name'=>'congmt'));
$congmtInfo= $congmtDeveloper->info();
$this->assertSame('matico-VN-PHP', $maticoInfo);
$this->assertSame('congmt-VN-PHP', $congmtInfo);
查看测试用例中的示例详细信息