在其他 Plugin ZF2 中调用 Plugin [英] Call Plugin in other Plugin ZF2

查看:33
本文介绍了在其他 Plugin ZF2 中调用 Plugin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Zend Framework 2 中,我记得有一个插件模块 A 插件模块 B.

in Zend Framework 2 as I can recall a plugin module A plug-in module B.

如果你从控制器中调用插件,它可以在任何地方工作,但我需要在另一个插件中调用一个插件.

If you recall the plugin from the controller, it works everywhere, but I need to call a plugin in another plugin.

我该怎么办?

推荐答案

你基本上必须将 PluginA 注入 PluginB.即:

You basically have to inject PluginA into PluginB. I.e:

$pluginA = new PluginA();
$pluginB = new PluginB($pluginA);
echo $pluginB("Hello World");

class PluginB {
    protected $pluginA;
    public function __construct(PluginA $pluginA) {
        $this->pluginA = $pluginA;
    }

    public function __invoke($arg) {
        $step1 = $this->doSomething($arg);
        return $this->pluginA->doSomeOtherPluginAThing($step1);
    } 
}

最终您的解决方案看起来会有所不同,您将通过 ServiceManager Factories 进行注入

Ultimately your Solution would look a little different and you'd do the injection via ServiceManager Factories

这篇关于在其他 Plugin ZF2 中调用 Plugin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆