0

loadModule();在 class 中有一个函数core,但是要加载模块,我需要在构造中定义变量,其中许多需要 core. 我会简单地使用loadModule("someModule", $settings, $dbc, $core, $etc...);还是loadModule("someModule", $settings, $dbc, $this, $etc...);因为这个函数在 $core 定义的核心类中?我现在很困惑,不胜感激。谢谢

编辑:

预期用途看起来像 $this->core->loadModule("initialLoad, $settings, $version, $dbc, $parser, $layout);

模块构造看起来像

public function __construct($settings, $version, $dbc, $layout, $core, $parser){
    $this->settings = $settings;
    $this->version = $version;
    $this->dbc = $dbc;
    $this->layout = $layout;
    $this->core = $core;
    $this->parser = $parser;

}
4

1 回答 1

0

我会研究依赖注入。也许使用类似pimple的东西。

让您的容器初始化所有模块。如果您需要进行更高级的使用,您可能会代理这些服务,以便它们在第一次使用时延迟实例化。

然后,您可能可以将核心注入到类中并使用您喜欢的加载模块。

于 2015-06-27T02:42:03.610 回答