m-r-r/lazy-container
Composer 安装命令:
composer require m-r-r/lazy-container
包简介
Smallest possible Dependency Injection container
README 文档
README
Usage
require __DIR__ . '/vendor/autoload.php'; use LazyContainer\Container; class Foo { public $name; function __construct($name) { echo "Instance of Foo created with name \"$name\".\n"; } } class Bar { public $foo; function __construct(Container $c) { echo "Instance of Bar created.\n"; $this->foo = $c->foo; } } class Baz { public $foo; public $bar; function __construct(Container $c) { echo "Instance of Baz created.\n"; $this->bar = $c->bar; $this->foo = $c->foo; } } $cont = new Container; $cont->foo = function($self, $cfg) { return new Foo($self->fooName); }; $cont->bar = function($self) { return new Bar($self); }; $cont->baz = function($self) { return new Baz($self); }; $cont->fooName = 'Quux'; // Later: var_dump($cont->baz instanceOf Baz && $cont->baz->bar === $cont->bar && $cont->baz->foo === $cont->bar->foo);
This program would print:
Instance of Baz created.
Instance of Bar created.
Instance of Foo created with name "Quux".
bool(true)
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2014-09-21