/** * Load languages * * @return bool Return true when language has been loaded. false otherwise */ protected function loadLangMap() { // Set LanguageMap first, because we need to tell application, // we already tried to get lang file so it will not waste time retrying it. $this->pool['LanguageMap'] = $typedLangData = $langMapTemp = $errors = array(); $compiledLangFile = $this->configs['Compiled'] . Framework::DIRECTORY_SEPARATOR . 'compiledLanguage.' . $this->pool['Language'] . '.php'; $langContent = $defaultLangContent = $langKey = $langVal = ''; if ($this->configs['Renew'] || !($this->pool['LanguageMap'] = static::loadDataCache($compiledLangFile, $this->configs['CacheBegin']))) { Framework::summonHook('template_load_language', array(), $errors); // load default lang file then client lang file // Must load default lang first foreach ($this->getLanguageFormMap('default') as $file) { if (is_readable($file)) { $defaultLangContent .= file_get_contents($file) . "\n"; } else { new Error('LANGUAGE_DEFAULT_FILE_NOTFOUND', array($file), 'ERROR'); return false; } } // And then, the client lang if ($this->pool['Language'] != 'default') { foreach ($this->getLanguageFormMap($this->pool['Language']) as $file) { if (is_readable($file)) { $langContent .= file_get_contents($file) . "\n"; } else { new Error('LANGUAGE_FILE_NOTFOUND', array($file), 'WARNING'); } } } foreach (array('Default' => explode("\n", $defaultLangContent), 'Client' => explode("\n", $langContent)) as $langType => $langMapPre) { foreach ($langMapPre as $lang) { $langMapTemp = explode('=', $lang, 2); if (!isset($langMapTemp[1])) { // If $langMapTemp[1] not set, may means this is just a comment. continue; } $langKey = trim($langMapTemp[0]); $langVal = trim($langMapTemp[1]); if (isset($typedLangData[$langType][$langKey])) { new Error('LANGUAGE_KEY_ALREADY_DECLARED', array($langKey, $typedLangData[$langType][$langKey]), 'WARNING'); break; } $this->pool['LanguageMap'][$langKey] = $langVal; $typedLangData[$langType][$langKey] = $langVal; } } if ($this->saveDataCache($compiledLangFile, $this->pool['LanguageMap'])) { return true; } } return false; }
/** * Automatically initialize a class and execute a method of it * * @param object $app Calling string with ClassName::MethodName format * @param array $args Arguments of calling * @param bool $cache Load the cached instance, and cache it after initialize. * * @return mixed|bool Return the result of called method when success, false otherwise */ public function run($app, array $args = array(), $cache = false) { $callResult = null; $errors = array(); $appParam = explode('::', str_replace(array('::', '->'), '::', $app), 2); if (!($handler = $this->getInstance($appParam[0], $args, $cache))) { return false; } if (isset($appParam[1]) && method_exists($handler, $appParam[1])) { $hookResult = Framework::summonHook('call_' . $appParam[0] . '::' . $appParam[1] . '_before', $args, $errors); $callResult = $this->callFunction(array($handler, $appParam[1]), $args); Framework::summonHook('call_' . $appParam[0] . '::' . $appParam[1] . '_after', array('Call' => $callResult, 'Hook' => $hookResult), $errors); } elseif (method_exists($handler, 'run')) { $hookResult = Framework::summonHook('call_' . $appParam[0] . '_before', $args, $errors); $callResult = $this->callFunction(array($handler, 'run'), $args); Framework::summonHook('call_' . $appParam[0] . '_after', array('Call' => $callResult, 'Hook' => $hookResult), $errors); } return $handler; }