herrera-io/service-container
最新稳定版本:1.1.0
Composer 安装命令:
composer require herrera-io/service-container
包简介
A simple service container.
README 文档
README
A simple service container.
Summary
This library provides a simple service container. It is heavily influenced by Fabien Potencier's Pimple project (in particular, Igor Wielder's modifications). The differences from Pimple are
- naming convention
- handling of service provider registration
- library specific exceptions
- different implementations of
shared()andprotect()
Installation
Add it to your list of Composer dependencies:
$ composer require herrera-io/service-container=1.*
Usage
Simple usage
<?php use Herrera\Service\Container; $container = new Container(array('var' => 123)); $container['factory'] = $container->many(function () { return new ArrayObject(array('rand' => rand())); }); $container['shared'] = $container->once(function() { return new ArrayObject(array('rand' => rand())); }); echo $container['factory']['rand']; // echo "1197692050" echo $container['factory']['rand']; // echo "995449132" echo $container['shared']['rand']; // echo "89432412" echo $container['shared']['rand']; // echo "89432412"
Service provider usage
<?php use Herrera\Service\Container; use Herrera\Service\ProviderInterface; class MyProvider implements ProviderInterface { public function register(Container $container) { $container['hello'] = $container->once(function (Container $container) { echo 'Hello, ', $container['name'], "!\n"; }); } } $container = new Container(); $container->register(new MyProvider(), array( 'name' => 'Guest' ));
统计信息
- 总下载量: 895
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 0
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-01-31