/** * Load language settings * * @access public * @param void * @throws DirDnxError If language dir does not exists * @throws FileDnxError If language settings file for this local settings * does not exists in lanuage dir */ private function loadLanguageSettings() { // Check dir... if (!is_dir($this->getLanguageDirPath())) { throw new DirDnxError($this->getLanguageDirPath()); } // if // Get settings file path and include it $settings_file = $this->getLanguageDirPath() . '/' . $this->getLocale() . '.php'; if (is_file($settings_file)) { include $settings_file; } else { throw new FileDnxError($settings_file, "Failed to find language settings file. Expected location: '{$settings_file}'."); } // if // Clear langs $this->langs->clear(); // Get langs dir $langs_dir = $this->getLanguageDirPath() . '/' . $this->getLocale(); if (is_dir($langs_dir)) { $files = get_files($langs_dir, 'php'); // Loop through files and add langs if (is_array($files)) { sort($files); foreach ($files as $file) { $langs = (include $file); if (is_array($langs)) { $this->langs->append($langs); } } // foreach } // if //Load plugin langs after fengoffice default langs $plugins_dir = $langs_dir . '/plugins'; if (is_dir($plugins_dir)) { sort($files); $files = get_files($plugins_dir, 'php'); // Loop through files and add langs if (is_array($files)) { foreach ($files as $file) { $langs = (include $file); if (is_array($langs)) { $this->langs->append($langs); } } // foreach } // if } // if } else { throw new DirDnxError($langs_dir); } // if // Done! return true; }
/** * Load language settings * * @param void * @throws DirDnxError If language dir does not exists * @throws FileDnxError If language settings file for this local settings * does not exists in lanuage dir */ private function loadLanguageSettings() { trace(__FILE__, 'loadLanguageSettings()'); // Check dir... $language_dir = $this->getLanguageDirPath(); if (!is_dir($language_dir)) { throw new DirDnxError($language_dir); } // if $locale = $this->getLocale(); $locale_dir = $language_dir . '/' . $locale; if (!is_dir($locale_dir)) { throw new DirDnxError($locale_dir); } // if // Get settings file path and include it $settings_file = $locale_dir . '/' . $locale . '.php'; if (!is_file($settings_file)) { trace(__FILE__, 'loadLanguageSettings()'); throw new FileDnxError($settings_file, "Failed to find language settings file" . $settings_file); } trace(__FILE__, 'loadLanguageSettings():include_once ' . $settings_file); include_once $settings_file; // Clear langs $this->langs->clear(); // Load core language files $this->loadLanguageFiles($locale_dir); // load every plugin language files $dirs = get_dirs(PLUGINS_DIR, false); foreach ($dirs as $plugin_dir) { if (plugin_active($plugin_dir)) { // plugin_dir is same as plugin name $locale_dir = PLUGINS_DIR . '/' . $plugin_dir . '/language/' . $locale; if (is_dir($locale_dir)) { $this->loadLanguageFiles($locale_dir); } else { //$locale_dir = PLUGINS_DIR.'/'.$plugin_dir.'/language/en_us'; if (is_dir($locale_dir)) { $this->loadLanguageFiles($locale_dir); } // if } // if } // if } // foreach // Done! return true; }
<?php error_reporting(E_ALL | E_STRICT); require_once '../anewt.lib.php'; /* Test constructor */ $c = new Container(array('foo' => 'bar')); assert('$c->get("foo") === "bar"'); /* Test clear() */ $c = new Container(); $c->set('foo', 'foo_value'); $c->set('bar', 'bar_value'); $c->clear(); /* Test custom getters and setters */ class TestContainer extends Container { function get_foo() { return 'foo_value'; } function get_baz($param = 'default') { return 'baz_value_' . $param; } } $test = new TestContainer(); $test->set('bar', 'bar_value'); /* Test keys() */ $keys = $test->keys(); assert('array_has_value($keys, "bar") === true'); assert('array_has_value($keys, "foo") === true'); assert('array_has_value($keys, "baz") === true');
/** * Load language settings * * @access public * @param void * @throws DirDnxError If language dir does not exists * @throws FileDnxError If language settings file for this local settings * does not exists in lanuage dir */ private function loadLanguageSettings() { // Check dir... if (!is_dir($this->getLanguageDirPath())) { throw new DirDnxError($this->getLanguageDirPath()); } // if // Get settings file path and include it $settings_file = $this->getLanguageDirPath() . '/' . $this->getLocale() . '.php'; if (is_file($settings_file)) { include $settings_file; } else { $base_settings = $this->getLanguageDirPath() . '/default.php'; if (is_file($base_settings)) { include $base_settings; } else { throw new FileDnxError($settings_file, "Failed to find language settings file. Expected location: '{$settings_file}'."); } } // Clear langs $this->langs->clear(); // Get langs dir - ONLY PHP langs ! $langs_dir = $this->getLanguageDirPath() . '/' . $this->getLocale(); if (is_dir($langs_dir)) { $files = get_files($langs_dir, 'php'); // Loop through files and add langs if (is_array($files)) { sort($files); foreach ($files as $file) { $langs = (include $file); if (is_array($langs)) { $this->langs->append($langs); } } } // Plugins - Only PHP langs - include all installed plugins, no matter if they they have not been activated $plugins = Plugins::instance()->getAll(); foreach ($plugins as $plugin) { /* @var $plugin Plugin */ $plg_dir = $plugin->getLanguagePath() . "/" . $this->getLocale(); if (is_dir($plg_dir)) { $files = get_files($plg_dir, 'php'); // Loop through files and add langs if (is_array($files)) { sort($files); foreach ($files as $file) { $langs = (include $file); if (is_array($langs)) { $this->langs->append($langs); } } } } } } else { throw new DirDnxError($langs_dir); } // if // Done! return true; }