0

I have a function loadModule(); in class core, but to load modules I need to define variables in the construct, and many of them require core. Would I simply use loadModule("someModule", $settings, $dbc, $core, $etc...); or loadModule("someModule", $settings, $dbc, $this, $etc...); since this function is in the core class that is defined by $core? I'm confused right now, and help would be appreciated. Thanks

EDIT:

Intended use would look something like $this->core->loadModule("initialLoad, $settings, $version, $dbc, $parser, $layout);

The module construct would look like

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;

}
Diptendu
  • 2,120
  • 1
  • 15
  • 28
Core
  • 335
  • 1
  • 11

1 Answers1

0

I would look into dependency injection. Perhaps use something like pimple.

Have your container initialize all your modules. If you need to get into more advance use you could probably proxy the services so that they're lazy instantiate at first time use.

Then you could probably inject core into the classes and use the loaded modules however you like.

slik
  • 5,001
  • 6
  • 34
  • 40
  • So this (and Rasclatt's comment(s)) led me to an idea; having the module loader in the page initiation class. Technically this would make more sense because it's not used much and would eliminate this problem – Core Jun 27 '15 at 02:47