/** * Retrieves modules and doing initialization */ public function init() { $config = $this->environment->getConfig(); $hasHooksPrefix = $config->has('hooks_prefix'); $modules = $this->getModulesList(); /** @var Rsc_Mvc_Module $instance */ foreach ($modules as $name => $instance) { /* Set http request to the module */ $instance->setRequest($this->request)->onInit(); /* Register hooks */ $index = $this->environment->getPluginPath() . '/index.php'; // register_activation_hook($index, array($instance, 'onInstall')); register_deactivation_hook($index, array($instance, 'onDeactivation')); if ($name === 'installer') { register_uninstall_hook($index, array(get_class($instance), 'onUninstall')); } /* We add module's location to the template & config loaders */ /** @var Twig_Loader_Filesystem $loader */ try { $loader = $this->environment->getTwig()->getLoader(); $loader->addPath($instance->getLocation() . '/views', strtolower($name)); // Add PRO module path to the @namespace. if ($instance->getOverloadController()) { $prefix = $config->get('pro_modules_prefix'); $location = $config->get('pro_modules_path') . DIRECTORY_SEPARATOR . $prefix . DIRECTORY_SEPARATOR . ucfirst($name); $loader->addPath($location . '/views', strtolower($name) . '_pro'); } } catch (Twig_Error_Loader $e) { } $configLoader = $config->getLoader(); $configLoader->add($instance->getLocation() . '/configs', strtolower($name)); if ($instance->getOverloadController()) { $prefix = $config->get('pro_modules_prefix'); $location = $config->get('pro_modules_path') . DIRECTORY_SEPARATOR . $prefix . DIRECTORY_SEPARATOR . ucfirst($name); $configLoader->add($location . '/configs', strtolower($name) . '_pro'); } /* Add module to the resolver */ $this->modules->add(strtolower($name), $instance); if ($hasHooksPrefix) { do_action($config->get('hooks_prefix') . 'after_' . strtolower($name) . '_loaded', $this->modules[strtolower($name)]); } // Try to load global configs for the current module. $basepath = $this->environment->getPluginPath() . '/app/configs'; $filepath = '/modules/' . $instance->getModuleName() . '.php'; if (file_exists($basepath . $filepath)) { $config = $this->environment->getConfig(); $config->load($filepath); } } if ($hasHooksPrefix) { do_action($config->get('hooks_prefix') . 'after_modules_loaded'); } }