/** * Configures the application. * * First this method tries to load a configuration from a configuration file in * the given configration directory using Piece_Unity_Config_Factory::factory(). * This method creates a new object if the load failed. * Second this method merges the given configuretion into the loaded * configuration. * Finally this method sets the configuration to the current context. * * @param string $configDirectory * @param string $cacheDirectory * @param Piece_Unity_Config $dynamicConfig * @since Method available since Release 1.5.0 */ function configure($configDirectory = null, $cacheDirectory = null, $dynamicConfig = null) { $this->_config =& Piece_Unity_Config_Factory::factory($configDirectory, $cacheDirectory); if (is_a($dynamicConfig, 'Piece_Unity_Config')) { $this->_config->merge($dynamicConfig); } $context =& Piece_Unity_Context::singleton(); $context->setConfiguration($this->_config); }
/** * Gets a Piece_Unity_Config object from a configuration file or a cache. * * @param string $masterFile * @param string $cacheDirectory * @return Piece_Unity_Config */ function &_getConfiguration($masterFile, $cacheDirectory) { $masterFile = realpath($masterFile); $cache =& new Cache_Lite_File(array('cacheDir' => "{$cacheDirectory}/", 'masterFile' => $masterFile, 'automaticSerialization' => true, 'errorHandlingAPIBreak' => true)); if (!Piece_Unity_Env::isProduction()) { $cache->remove($masterFile); } /* * The Cache_Lite class always specifies PEAR_ERROR_RETURN when * calling PEAR::raiseError in default. */ $config = $cache->get($masterFile); if (PEAR::isError($config)) { trigger_error("Cannot read the cache file in the directory [ {$cacheDirectory} ].", E_USER_WARNING); return Piece_Unity_Config_Factory::_getConfigurationFromFile($masterFile); } if (!$config) { $config =& Piece_Unity_Config_Factory::_getConfigurationFromFile($masterFile); $result = $cache->save($config); if (PEAR::isError($result)) { trigger_error("Cannot write the Piece_Unity_Config object to the cache file in the directory [ {$cacheDirectory} ].", E_USER_WARNING); } } return $config; }