/** * Load config for application modules * * @return void */ public function load() { $app = \Magelight\App::getInstance(); $loader = \Magelight\Components\Loaders\Config::forge(); $loader->loadConfig($app->getAppDir() . DS . 'etc' . DS . 'config.xml'); $this->config = $loader->getConfig(); $modulesConfigString = $this->getConfigBool('global/app/cache_modules_config', false) ? $this->cache()->get($this->buildCacheKey('modules_config')) : false; /* Loading modules config */ if (!$modulesConfigString) { $loader->setConfig($this->config); foreach (array_reverse($app->getModuleDirectories()) as $modulesDir) { foreach (\Magelight\Components\Modules::getInstance()->getActiveModules() as $module) { $filename = $loader->getModulesConfigFilePath($modulesDir, $module); if ($filename) { $loader->loadConfig($filename); } } } $modulesConfig = $loader->getConfig(); if ($this->getConfigBool('global/app/cache_modules_config', false)) { $this->cache()->set($this->buildCacheKey('modules_config'), $modulesConfig->asXML(), 3600); } $this->config = $modulesConfig; } else { $this->config = simplexml_load_string($modulesConfigString); } unset($loader); }
/** * Load application routes * * @return Routes */ public function loadRoutes() { $modules = \Magelight\Components\Modules::getInstance()->getActiveModules(); foreach (array_reverse(\Magelight\App::getInstance()->getModuleDirectories()) as $modulesPath) { foreach ($modules as $module) { $filename = $modulesPath . DS . str_replace('/', DS, $module['path']) . DS . 'etc' . DS . 'routes.xml'; if (file_exists($filename)) { $xml = simplexml_load_file($filename); $this->parseModuleRoutes($xml, $module['path']); } } } $this->routes = array_reverse($this->routes, true); return $this; }
/** * Load translations * * @param string $lang */ public function loadTranslations($lang) { if (!is_string($lang)) { throw new \InvalidArgumentException('Language must be a string'); } foreach (array_reverse(\Magelight\App::getInstance()->getModuleDirectories()) as $modulesDir) { foreach (\Magelight\Components\Modules::getInstance()->getActiveModules() as $module) { $filename = $modulesDir . DS . $module['path'] . DS . 'I18n' . DS . $lang . '.php'; if (file_exists($filename)) { $translations = (require $filename); $this->translations = array_replace_recursive($this->translations, $translations); } } } $filename = __DIR__ . DS . 'Preferences' . DS . $lang . '.php'; if (file_exists($filename)) { $plurals = (require_once $filename); $this->plurals = $plurals; } }
/** * Initialize application * * @return App * @throws \Magelight\Exception */ public function init() { $this->addModulesDir($this->getFrameworkDir() . DS . 'modules'); $this->addModulesDir($this->getFrameworkDir() . DS . 'modules'); $this->initIncludePaths(); \Magelight\Components\Modules::getInstance()->loadModules($this->getAppDir() . DS . 'etc' . DS . 'modules.xml'); \Magelight\Components\Modules::getInstance()->getActiveModules(); \Magelight\Config::getInstance()->load(); $this->setDeveloperMode((string) \Magelight\Config::getInstance()->getConfig('global/app/developer_mode')); if ($this->isInDeveloperMode()) { error_reporting(E_ALL); ini_set('display_errors', '1'); } \Magelight\Http\Session::getInstance()->setLifetime((int) \Magelight\Config::getInstance()->getConfig('global/app/session_lifetime', 1440))->setSessionName(self::SESSION_ID_COOKIE_NAME)->start(); $this->loadPreferences(); $lang = \Magelight\Http\Session::getInstance()->get('lang'); if (empty($lang)) { $lang = (string) \Magelight\Config::getInstance()->getConfig('global/app/default_lang'); } if (empty($lang)) { $lang = self::DEFAULT_LANGUAGE; } $this->setLang($lang); return $this; }
/** * Upgrade modules * * @return Installer * @codeCoverageIgnore */ public function upgrade() { foreach (\Magelight\Components\Modules::getInstance()->getActiveModules() as $module) { $scripts = $this->findInstallScripts($module['path']); foreach ($scripts as $script => $filename) { if (!$this->isSetupScriptExecuted($module['name'], $script)) { $this->executeScript($filename); $this->setSetupScriptExecuted($module['name'], $script); } } } return $this; }
/** * Crawl application for translations */ public function crawlApp() { $files = []; foreach (array_reverse(\Magelight\App::getInstance()->getModuleDirectories()) as $modulesDir) { foreach (\Magelight\Components\Modules::getInstance()->getActiveModules() as $module) { $path = $modulesDir . DS . $module['path']; if (is_readable($path)) { foreach ($this->_getModuleFilesList($path) as $foundFile) { $files[$path][$foundFile] = []; } } } } foreach ($files as $modulePath => $filesList) { foreach ($filesList as $filePath => $translations) { echo 'fetching translations for ' . $filePath . PHP_EOL; $translations = $this->_getTokenizer()->findTranslations($filePath); if (!empty($translations)) { if (!isset($this->_phrases[$modulePath])) { $this->_phrases[$modulePath] = []; } $this->_phrases[$modulePath] = array_merge_recursive($this->_phrases[$modulePath], $translations); } } } $this->_processLanguagePreferences(); }