/** * Добавляет конфиг в реестр, сливает с конфигом-патчем (если есть) * * @param string $file * @throws Zend_Application_Exception When invalid configuration file is provided * @return array */ protected function _loadConfig($file) { $environment = $this->getEnvironment(); $config = new Zend_Config_Ini($file, $environment, true); # Получаем путь к дополнительному конфигу $additionConfig = isset($config->config) ? $config->config : dirname($file) . '/_' . basename($file); if (is_readable($additionConfig)) { try { $configCustom = new Zend_Config_Ini($additionConfig, $environment); $config->merge($configCustom); } catch (Zend_Config_Exception $e) { } } if (isset($config->config)) { unset($config->config); } $config->setReadOnly(); Zend_Registry::set('config', $config); return $config->toArray(); }
/** * Loads the configuration * * First, the main configuration file - "application.ini" - is loaded from * the root of the configs directory. Second, all other configuration files, * if any, are loaded recursively - except for "user.ini". Third, the * developer-specific configuration file - "user.ini" - is loaded. This * file overrides any setting in the previously loaded files and is only * regarded in development and testing mode. * * This method must be 'public static' - Zend_Cache_Class requires so. * However, users shouldn't call it directly; use getConfig() instead. * * @param string $section * @return Zend_Config */ public static function loadConfig($section) { // Load the main configuration file $configFile = GLITCH_CONFIGS_PATH . DIRECTORY_SEPARATOR . self::FILENAME_APPLICATION; $ini = new Zend_Config_Ini($configFile, $section, array('allowModifications' => true)); // Recursively load all other ini files, if any, but exclude the special cases $pattern = '~^(?!' . preg_quote(self::FILENAME_APPLICATION) . '|' . preg_quote(self::FILENAME_USER) . ').+\\.ini$~'; $dirIterator = new RecursiveDirectoryIterator(GLITCH_CONFIGS_PATH, RecursiveDirectoryIterator::KEY_AS_FILENAME); $recursiveIterator = new RecursiveIteratorIterator($dirIterator); $iterator = new RegexIterator($recursiveIterator, $pattern, RegexIterator::MATCH, RegexIterator::USE_KEY); foreach ($iterator as $file) { $ini->merge(new Zend_Config_Ini($file->getPathname(), $section)); } // Optionally load developer-specific settings, overriding previous settings $configFile = GLITCH_CONFIGS_PATH . DIRECTORY_SEPARATOR . self::FILENAME_USER; if (('development' == $section || 'testing' == $section) && file_exists($configFile)) { $ini->merge(new Zend_Config_Ini($configFile, $section)); } if ('testing' != $section) { $ini->setReadOnly(); } return $ini; }
$locale = new Zend_Locale('fr_CA'); Zend_Registry::set('Zend_Locale', $locale); // loading configuration $host = explode('.', $_SERVER['HTTP_HOST']); $envVar = 'production'; if (in_array('sandboxes', $host) || in_array('localhost', $host)) { $envVar = 'development'; } elseif (in_array('staging', $host)) { $envVar = 'staging'; } $config = new Zend_Config_Ini("{$application_path}/config.ini", 'general', true); $imgCfg = new Zend_Config_Ini("{$application_path}/config.ini", 'Images', true); $envCfg = new Zend_Config_Ini("{$application_path}/config.ini", $envVar); $config->merge($imgCfg); $config->merge($envCfg); $config->setReadOnly(); $registry = Zend_Registry::getInstance(); $registry->set('config', $config); // establishment of the database $db = Zend_Db::factory($config->db); Zend_Db_Table::setDefaultAdapter($db); $db->query('SET NAMES utf8'); $registry->set('db', $db); $registry->set('siteName', $config->site->title); $registry->set('application_path', $application_path); $registry->set('orders_path', $orders_path); $registry->set('document_root', "{$rootDir}/{$config->document_root}"); $registry->set('web_root', $web_root); $registry->set('www_root', $web_root); $registry->set('absolute_web_root', $absolute_web_root); $registry->set('lucene_index', realpath(dirname(__FILE__)) . "/indexation/all_index");