public function init() { // Just in cas something goes wrong before the end // @todo replace with a setTemplate() in t41\Exception View::setTemplate('default.html'); // get page identifiers (module, controller and action) Layout::$module = $this->_getParam('module'); Layout::$controller = $this->_getParam('controller'); Layout::$action = $this->_getParam('action'); // provide controller with basic information about the current module foreach (Module::getConfig() as $vendor => $modules) { foreach ($modules as $key => $module) { if (isset($module['controller']) && Layout::$module == $module['controller']['base']) { $this->_module = 'app/' . $vendor . '/' . $key; Layout::$vendor = $vendor; Layout::$moduleKey = $key; $resource = Layout::$controller; if (Layout::$action) { $resource .= '/' . Layout::$action; } if (isset($module['controller']['items'])) { foreach ($module['controller']['items'] as $controller) { if ($this->_getCurrentItem($resource, $controller) == true) { break; } } } if (isset($module['controllers_extends'])) { foreach ($module['controllers_extends'] as $controller) { if ($this->_getCurrentItem($resource, $controller['items']) == true) { break; } } } break; } } } }
/** * Detect all modules directories and try to get config for them * @param string $path */ public static function init($path) { self::$_path = $path . 'application/modules' . DIRECTORY_SEPARATOR; if (!is_dir(self::$_path)) { return false; } // get config from cache if (Core::getEnvData('cache_configs') == "bogus") { $ckey = 'configs_modules'; if (($cached = Core::cacheGet($ckey)) !== false) { self::$_config = $cached; } } if (true) { //! self::$_config) { self::$_config = array(); self::$_modules = array('enabled' => array(), 'disabled' => array()); foreach (scandir(self::$_path) as $vendor) { if (is_dir(self::$_path . $vendor) && substr($vendor, 0, 1) != '.') { foreach (scandir(self::$_path . $vendor) as $entry) { $fpath = self::$_path . $vendor . DIRECTORY_SEPARATOR . $entry . DIRECTORY_SEPARATOR; if (is_dir($fpath) && substr($entry, 0, 1) != '.') { if (is_dir($fpath . 'configs')) { // register path with $vendor as prefix Config::addPath($fpath . 'configs', Config::REALM_MODULES, null, $vendor); } } } } } // load all detected modules configuration file $config = Config\Loader::loadConfig('module.xml', Config::REALM_MODULES); // remove useless "modules" key foreach ($config as $key => $val) { self::$_config[$key] = $val['modules']; } // cache config if cache is enabled if (isset($ckey)) { Core::cacheSet(self::$_config, $ckey); } } unset($ckey); // build menu if (Core::getEnvData('cache_configs') == "bogus") { $ckey = 'configs_menu_main'; if (($cached = Core::cacheGet($ckey)) !== false) { $menu = $cached; } } if (true) { //! isset($menu)) { $menu = new Layout\Menu('main'); $menu->setLabel('Main Menu'); foreach (self::$_config as $prefix => $modules) { foreach ($modules as $key => $module) { if ($module['enabled'] != 'true') { continue; } $path = Core::$basePath . 'application/modules' . DIRECTORY_SEPARATOR . $prefix . DIRECTORY_SEPARATOR . $key; self::bind($module, $path); // if module has controllers, declare them to front controller // then add them to main menu if (isset($module['controller']) || isset($module['controllers_extends'])) { Config::addPath($path . '/controllers/', Config::REALM_CONTROLLERS, null, $module['controller']['base']); } if (isset($module['controller'])) { $menu->addItem($module['controller']['base'], $module['controller']); } // if module extends existing controllers, declare them for inclusion at the end of the process if (isset($module['controllers_extends']) && !empty($module['controllers_extends'])) { $menu->registerExtends($module['controller']['base'], $module['controllers_extends']); } } } // process extends declaration when menu is complete $menu->proceedExtends(); if (isset($ckey)) { Core::cacheSet($menu, $ckey); } } Layout::addMenu('main', $menu); }