public static function loadConfig($path, $environment, $recursivelyLoadModuleConfig = false) { self::$_environment = $environment; if (is_string($path) && is_dir($path)) { $iterator = new Centurion_Iterator_Directory($path); $tabFile = array(); foreach ($iterator as $file) { if ($file->isDot()) { continue; } $tabFile[] = $file->getPathName(); } if (0 == count($tabFile)) { return array(); } sort($tabFile); $backendOptions = array('cache_dir' => APPLICATION_PATH . '/../data/cache/config/'); $frontendOptions = array('master_files' => array_values($tabFile), 'automatic_serialization' => true, 'cache_id_prefix' => str_replace('-', '_', $environment)); try { $cacheConfig = Zend_Cache::factory('File', 'File', $frontendOptions, $backendOptions); } catch (Exception $e) { self::$_noCache = true; } if (self::$_noCache || !($config = $cacheConfig->load(md5(implode('|', $tabFile))))) { $config = array(); foreach ($tabFile as $file) { $suffix = strtolower(pathinfo($file, PATHINFO_EXTENSION)); switch ($suffix) { case 'ini': case 'xml': case 'php': case 'inc': $result = self::_loadConfig($file); $config = self::mergeArrays($config, $result); } } if (!self::$_noCache) { $cacheConfig->save($config); } } if ($recursivelyLoadModuleConfig && isset($config['resources']) && isset($config['resources']['modules'])) { foreach ($config['resources']['modules'] as $module) { $dir = null; if (file_exists(APPLICATION_PATH . '/../library/Centurion/Contrib/' . $module . '/configs')) { $dir = APPLICATION_PATH . '/../library/Centurion/Contrib/' . $module . '/configs'; } else { if (file_exists(APPLICATION_PATH . '/modules/' . $module . '/configs')) { $dir = APPLICATION_PATH . '/modules/' . $module . '/configs'; } } if (null !== $dir) { $result = self::loadConfig($dir, $environment); $config = self::mergeArrays($result, $config); } } } return $config; } throw new Centurion_Exception('Path must be a directory', 500); }
/** * Clear cache with "clear cache" command. */ public function clear($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = null, $environment = self::DEFAULT_ENVIRONMENT) { $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION); define('APPLICATION_PATH', $this->_loadedProfile->search('applicationDirectory')->getPath()); $config = Centurion_Config_Directory::loadConfig(APPLICATION_PATH . '/configs', $environment); $cacheManager = new Centurion_Cache_Manager(); $options = $config['resources']['cachemanager']; foreach ($options as $key => $value) { if ($cacheManager->hasCacheTemplate($key)) { $cacheManager->setTemplateOptions($key, $value); } else { $cacheManager->setCacheTemplate($key, $value); } } if (null === $tags || !is_array($tags) && !is_string($tags)) { $tags = array(); } if (is_string($tags)) { $tags = explode(',', $tags); } foreach ($cacheManager->getBackends() as $key => $cache) { $this->_registry->getResponse()->appendContent(sprintf(">>> (%s) %s", $key, get_class($cache))); if ($cache instanceof Zend_Cache_Backend_ExtendedInterface) { switch ($mode) { case Zend_Cache::CLEANING_MODE_ALL: $ids = $cache->getIds(); break; case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG: $ids = $cache->getIdsMatchingAnyTags($tags); break; case Zend_Cache::CLEANING_MODE_MATCHING_TAG: $ids = $cache->getIdsMatchingTags($tags); break; case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG: $ids = $cache->getIdsNotMatchingTags($tags); break; case Zend_Cache::CLEANING_MODE_OLD: $ids = $cache->getIds(); break; } } else { $this->_registry->getResponse()->appendContent('not extended'); } $cache->clean($mode, $tags); if ($cache instanceof Zend_Cache_Backend_ExtendedInterface) { if ($mode === Zend_Cache::CLEANING_MODE_OLD) { $ids = array_diff($ids, $cache->getIds()); } if (count($ids)) { foreach ($ids as $val) { $this->_registry->getResponse()->appendContent(sprintf('>> %-9s %s', 'id-', $val)); } } } } if ($mode === Zend_Cache::CLEANING_MODE_ALL) { Centurion_Loader_PluginLoader::clean(); } }
public function __construct($name = NULL, array $data = array(), $dataName = '') { if (null == $this->bootstrap) { // Assign and instantiate in one step: $this->bootstrap = new Centurion_Application(APPLICATION_ENV, Centurion_Config_Directory::loadConfig(APPLICATION_PATH . '/configs/', APPLICATION_ENV, true)); } parent::__construct($name, $data, $dataName); }
/** * @throws Zend_Application_Exception * @param $environment * @param null $options */ public function __construct($environment, $options = null) { $this->_environment = (string) $environment; require_once 'Zend/Loader/Autoloader.php'; $this->_autoloader = Zend_Loader_Autoloader::getInstance(); if (is_string($options) && is_dir($options)) { $config = Centurion_Config_Directory::loadConfig($options, $environment); $this->setOptions($config); } else { if (null !== $options) { if (is_string($options)) { $options = $this->_loadConfig($options); } elseif ($options instanceof Zend_Config) { $options = $options->toArray(); } elseif (!is_array($options)) { throw new Zend_Application_Exception('Invalid options provided; must be location of config file, a config object, or an array'); } $this->setOptions($options); } } }
protected function _checkDbConnect() { if (!$this->_hasCenturion || !$this->_hasZend) { $this->_checklist[] = array('code' => -1, 'canBeBetter' => true, 'isNotSecure' => false, 'text' => 'Database could not be checked (no Centurion or Zend)', 'alt' => ''); } else { include_once __DIR__ . '/../../library/Centurion/Config/Directory.php'; include_once __DIR__ . '/../../library/Centurion/Iterator/Directory.php'; include_once __DIR__ . '/../../library/Zend/Config/Ini.php'; $config = Centurion_Config_Directory::loadConfig(__DIR__ . '/../../application/configs', $this->_currentEnv); include_once __DIR__ . '/../../library/Zend/Application/Resource/Db.php'; include_once __DIR__ . '/../../library/Zend/Db.php'; $this->_dbRessource = new Zend_Application_Resource_Db(); $this->_dbRessource->setParams($config['resources']['db']['params']); $this->_dbRessource->setAdapter($config['resources']['db']['adapter']); try { $bddVersion = $this->_dbRessource->getDbAdapter()->getServerVersion(); if (version_compare(PHP_VERSION, '5.1') >= 0) { $this->_checklist[] = array('code' => 1, 'canBeBetter' => false, 'isNotSecure' => false, 'text' => 'Mysql version <strong>' . $bddVersion . '</strong>', 'alt' => ''); } else { $this->_checklist[] = array('code' => -1, 'canBeBetter' => true, 'isNotSecure' => true, 'text' => 'Mysql version <strong>' . $bddVersion . '</strong>', 'alt' => ''); } } catch (Exception $e) { if ($e->getCode() == 1049) { $this->_checklist[] = array('code' => -1, 'canBeBetter' => true, 'isNotSecure' => true, 'text' => 'BDD ' . $config['resources']['db']['params']['dbname'] . ' does not exists', 'alt' => ''); } else { throw $e; } } } }
/** * @covers Centurion_Config_Directory::loadConfig */ public function testLoadConfigWithWrongParameter() { Centurion_Config_Directory::loadConfig(APPLICATION_PATH . '/../tests/support/configs/empty', 'test'); $this->setExpectedException('Centurion_Exception'); Centurion_Config_Directory::loadConfig(APPLICATION_PATH . '/../tests/support/this_diretory_does_not_exists', 'test'); }
/** * Retrieve import adapter. * * @param string $environment * @return Zend_Db_Adapter_Abstract */ protected function _getDbImport($environment = self::DEFAULT_ENVIRONMENT) { if (null === $this->_dbImport) { if (!$this->_loadedProfile) { $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION); } define('APPLICATION_PATH', $this->_loadedProfile->search('applicationDirectory')->getPath()); $config = Centurion_Config_Directory::loadConfig(dirname($this->_loadedProfile->search('applicationConfigFile')->getPath()), $environment); $dbAdapter = Zend_Db::factory(new Zend_Config($config['resources']['db'])); $this->_dbImport = Centurion_Import::factory($dbAdapter); } return $this->_dbImport; }