Ejemplo n.º 1
0
 /**
  * Gets a Piece_ORM_Config object from a cache.
  *
  * @param string $masterFile
  * @param string $cacheDirectory
  * @return Piece_ORM_Config
  */
 function &_getConfiguration($masterFile, $cacheDirectory)
 {
     $masterFile = realpath($masterFile);
     $cache =& new Cache_Lite_File(array('cacheDir' => "{$cacheDirectory}/", 'masterFile' => $masterFile, 'automaticSerialization' => true, 'errorHandlingAPIBreak' => true));
     if (!Piece_ORM_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_ORM_Config_Factory::_createConfigurationFromFile($masterFile);
     }
     if (!$config) {
         $config =& Piece_ORM_Config_Factory::_createConfigurationFromFile($masterFile);
         $result = $cache->save($config);
         if (PEAR::isError($result)) {
             trigger_error("Cannot write the Piece_ORM_Config object to the cache file in the directory [ {$cacheDirectory} ].", E_USER_WARNING);
         }
     }
     return $config;
 }
Ejemplo n.º 2
0
 /**
  * Configures the Piece_ORM environment.
  *
  * First this method tries to load a configuration from a configuration
  * file in the given configration directory using
  * Piece_ORM_Config_Factory::factory(). The method creates a new object
  * if the load failed.
  * Second this method sets the configuration to the current context.
  * And also this method sets the configuration directory for the mapper
  * configuration, and the cache directory for mappers, and the cache
  * directory for Piece_ORM_Metadata class.
  *
  * @param string $configDirectory
  * @param string $cacheDirectory
  * @param string $mapperConfigDirectory
  */
 function configure($configDirectory, $cacheDirectory, $mapperConfigDirectory)
 {
     $config =& Piece_ORM_Config_Factory::factory($configDirectory, $cacheDirectory);
     $context =& Piece_ORM_Context::singleton();
     $context->setConfiguration($config);
     $context->setMapperConfigDirectory($mapperConfigDirectory);
     $defaultDatabase = $config->getDefaultDatabase();
     if (!is_null($defaultDatabase)) {
         $context->setDatabase($defaultDatabase);
     }
     Piece_ORM_Mapper_Factory::setCacheDirectory($cacheDirectory);
     Piece_ORM_Metadata_Factory::setCacheDirectory($cacheDirectory);
     $GLOBALS['PIECE_ORM_Configured'] = true;
 }