asm89 / yac
另一个容器
dev-master / 0.1.x-dev
2013-11-14 15:09 UTC
Requires
- php: >=5.3.3
Requires (Dev)
- athletic/athletic: ~0.1.7
- pimple/pimple: 2.0.x-dev as v1.0.2
This package is auto-updated.
Last update: 2024-08-29 03:58:00 UTC
README
刚刚想起了 @crell 在 #tnphp 上的这个 gem:"再发明一个容器?你可以叫 YAC,然后剃掉它!" - igorwesome
另一个容器是 PHP 的另一个依赖注入容器,灵感来源于 Pimple 和 LazyMap。基本上是将两者结合起来。使用它时,按照 LazyMap 方式,性能非常出色。
定义参数
$c = new Yac\Yac(); $c['env'] = 'dev';
定义服务
$c['session'] = function($c) { return new Session($c->env); };
访问参数和服务
$std = $c['std']; // pimple compatible $std = $c->std; // "fast" LazyMap way
性能
Yac 比 Pimple 快得多!
$ php -n ./vendor/bin/athletic -p ./tests/YacPerformance/ -b ./tests/bootstrap.php -f GroupedFormatter YacPerformance\YacPerformanceEvent fetch_service-performance Method Name Iterations Average Time Ops/s Relative ------------------------------ ---------- ------------ -------------- --------- --------- pimpleFetchService : [Baseline] [100,000 ] [0.0000042015409] [238,007.91486] yacFetchServicePimpleStyle : [100,000 ] [0.0000032225394] [310,314.27956] [76.70%] yacFetchServiceLazyMapStyle : [100,000 ] [0.0000027879906] [358,681.27057] [66.36%] fetch_initialized_service-performance Method Name Iterations Average Time Ops/s Relative ------------------------------ ---------- ------------ -------------- --------- --------- pimpleFetchInitializedService : [Baseline] [100,000 ] [0.0000010025978] [997,408.92228] yacFetchInitializedServicePimpleStyle: [100,000 ] [0.0000007377648] [1,355,445.46456] [73.59%] yacFetchInitializedServiceLazyMapStyle: [100,000 ] [0.0000002871366] [3,482,663.50475] [28.64%]
已知限制
- 没有名为
__yac
的参数/服务 - 所有服务都是 "共享" 的,"原型" 服务尚不支持
- ...