modules **/ private $modules = array(); /** * @param \Tool\Context $context * Load all active modules from database. * Enable hooks for these modules * Disable them if the module cannot be loaded **/ public function __construct($context) { $this->context = $context; $modulesRoot = $context->router->modulesPath; $modules = \Entity\Module::getActivated(); $ids = array(); foreach ($modules as $i) { $modulePath = "{$modulesRoot}{$i->directory}/main.php"; if (file_exists($modulePath) && $this->loadModule($modulePath, $i)) { $ids[] = $i->id; } else { $i->active = false; $i->save(); } } \Tools\Hooks::loadHooks(\Entity\ModuleHook::getModules($ids)); } /** * @param string $path path to module's main file * @param \Entity\Module $module module's database object to load * /core/models/Module.php * @return TRUE on success * Will try to load module located at $path. * This function will include the main.php file located in the module's directory * The file MUST return an AModule object to be considered as successfull * /core/tools/AModule.php **/ private function loadModule($path, $module) { $this->modules[] = $module; return true; } /* * TODO revoir tout * @return array(AModule) * Will load every modules, and return them. **/ public function listAvailableModules() { $modulesRoot = $context->router->modulesPath; $result = array(); $modules = scandir($modulesRoot, SCANDIR_SORT_NONE); foreach ($modules as $i) { $path = $modulesRoot.$i; if ($i == '.' || $i == '..' || !is_dir($path)) continue; $this->loadModule($path); } } public function __get($key) { switch ($key) { case "modules": return $this->modules; break; } throw new \Exception("Cannot access attribute {$key}"); } }