mead-steve/container
Composer 安装命令:
composer require mead-steve/container
包简介
Simple Dependency Injection Container.
README 文档
README
Very basic dependency injection container.
Build status
| branch | status |
|---|---|
| master |
Example Usage
Setup a resource in the container:
use \Meadsteve\Container\Container; use \Meadsteve\Container\Singleton; $MyContainer = new Container(); $MyContainer->DependancyOne = new Dependancy(); $MyContainer->MyObject = function(Container $Container) { return new MyObject($Container->DependancyOne); };
Then when you need an instance of MyObject:
$InstanceOfMyObject = $MyContainer->MyObject;
For some heavy objects you may not want to run the construction logic each time. Then you may want to use the singleton pattern. This is possible with the provided class:
$MyContainer->DBUser = "DBGuy"; $MyContainer->Password = "SuperSecret10"; $MyContainer->DBBasedObject = new Singleton(function(Container $Container) { return new DBObject($Container->DBUser, $Container->Password); });
Which is then retrieved in exactly the same way:
$DBInstance = $MyContainer->DBBasedObject
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-01-31