scabbiafw / scabbia2-services
v0.1.2
2015-09-16 02:37 UTC
Requires
- php: >=5.6.0
Requires (Dev)
This package is not auto-updated.
Last update: 2022-02-01 12:51:18 UTC
README
此组件 是一个小型依赖项管理容器实现,允许您轻松共享、生成和访问实例/变量。
用法
基本键/值容器
use Scabbia\Services; $container = new Services(); $container['key'] = 'value'; echo $container['key'];
单例访问
use Scabbia\Services; $container = Services::getCurrent(); $container['key'] = ['sample', 'array']; var_dump($container['key']);
设置工厂
use Scabbia\Services; $container = Services::getCurrent(); $container->setFactory('key', function () { return ['time' => microtime(true)]; }); var_dump($container['key']); var_dump($container['key']); // will be different than previous one
装饰
use Scabbia\Services; $container = Services::getCurrent(); $container['key'] = 'test'; $container->decorate('key', function ($value) { return $value . 'ing'; }); $container->decorate('key', function ($value) { return strtoupper($value); }); var_dump($container['key']); // returns 'TESTING'
链接
贡献
对任何贡献都公开。欢迎修复错误、新功能和额外模块。所有贡献应提交到 eserozvataf/scabbia2-services 仓库。