glenjamin / dimple
极其简单的依赖注入容器
v0.1.0
2013-07-27 13:17 UTC
Requires
- php: >= 5.3
Requires (Dev)
- phpunit/phpunit: 3.7.x
- pimple/pimple: 1.0.x
This package is not auto-updated.
Last update: 2024-09-23 14:07:52 UTC
README
基于Pimple的简单依赖注入容器
安装
composer require glenjamin/dimple
用法
$di = new \Dimple\Dimple(); $di->setup('app', function($di) { return new Application($di->get('db'), $di->get('logger')); }); $di->setup('db', function($di) { return new \PDO($di->get('db-string')); }); $di->set('dbstring', 'mysql://'); $di->setup('logger', function($di) { return new Logger($di->get('logfile', '/dev/null')); }); $app = $di->get('app'); $app->run();
如何在上一次调用之后返回相同的实例?
你不需要这样做。
它快吗?
不幸的是,并不特别快,尽管它也不是太糟糕
> php benchmark.php
10000000 Iterations
Raw: 4.3745291233063
Dimpled: 14.07391500473
Overhead: 221.724113%
它的速度比原始对象初始化慢大约两倍。如果你只用于服务级别对象,应该可以接受。