pattisahusiwa / dice-wrapper
v1.3
2020-08-16 03:38 UTC
Requires
- php: >=7.0.0
- level-2/dice: ^4.0
- psr/container: ^1.0
Requires (Dev)
- phpunit/phpunit: ^6.5
This package is auto-updated.
Last update: 2020-09-02 21:51:08 UTC
README
此仓库已废弃。请使用 pattisahusiwa/dicontainer
Dice wrapper - PHP 依赖注入容器
PSR-11 兼容 Level-2/Dice 依赖注入容器。
Dice 是一个专注于轻量、快速且配置尽可能少的PHP依赖注入容器。
安装
使用 composer 安装此包。
composer require pattisahusiwa/dice-wrapper
使用
请查阅 Dice 文档 了解详细用法。
// Create new Dice instance $dice = new Dice(); // You can also pass your dependencies configuration into Dice instance $dice = $dice->addRules('rules.json'); // Pass dice instance to DiceWrapper $diceWrapper = new DiceWrapper($dice); // example usage if ($diceWrapper->has('class_name')) { $object = $diceWrapper->get('class_name'); }
限制
您不能使用 DICE::SELF
来获取 DiceWrapper
实例。 DICE::SELF
将返回 Dice
实例。
当前的解决方案是在您的类构造函数中添加 Psr\Container\ContainerInterface
。注入器和注入的 DiceWrapper
是同一个对象。然而,您必须小心地在项目中实现这一点,因为它可能会变成一个 服务定位器。
<?php use Psr\Container\ContainerInterface; final class ExampleClass { public function __construct(ContainerInterface $dic) { } }
贡献
欢迎所有形式的贡献。您可以 报告问题、分支此仓库并提交拉取请求。
许可
请参阅 LICENSE 文件。