swisnl / zf-ioc
此包已被废弃且不再维护。未建议替代包。
使用Laravel的IoC容器在Zend Framework 1中进行控制器动作依赖注入。
0.2.1
2018-03-27 07:36 UTC
Requires
- php: >=5.4.0
- illuminate/container: ^5.0
This package is auto-updated.
Last update: 2023-02-16 20:11:11 UTC
README
🚨 此包已被废弃 🚨
我们不再在我们的项目中使用此包,也无法证明继续维护它所需的时间。这就是我们选择废弃它的原因。欢迎您fork我们的代码并维护自己的副本或使用众多替代方案之一。
ZF-IoC
在Zend Framework 1中进行控制器动作依赖注入。
不将框架作为composer依赖项,以支持旧项目(因为这是此包存在的唯一原因)。
当前需要PHP 5.4+(由illuminate/container 5.0要求)
composer require jeroenvandergeer/zf-ioc
// Container of choice, can be any Laravel compatible container $container = new \Illuminate\Container\Container(); // Build dispatcher with IoC container $dispatcher = new \Jeroenvandergeer\ZfIoc\Dispatcher($container); // Set / replace the dispatcher $frontController = \Zend_Controller_Front::getInstance(); $frontController->setDispatcher($dispatcher); // Optionally register the container with the Zend registry for global binding \Zend_Registry::set('container', $container); // Register binding $container->bind('\App\FooInterface', function($container){ return new \App\Foo($container['\App\Bar']); });
示例 #1
public function indexAction(\App\FooInterface $foo) { var_dump($foo); }
object(App\Foo)
public 'bar' =>
object(App\Bar)
示例 #2
public function indexAction() { $container = $this->getInvokeArg('container'); var_dump($container->make('\App\Foo')); }
object(App\Foo)
public 'bar' =>
object(App\Bar)