/** * 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; }
/** * Invokes the plugin specific code. * * @param boolean $isProduction */ function invoke($isProduction) { Piece_ORM_Env::setIsProduction($isProduction); }
/** * Gets a mapper source by either generating from a configuration file or * getting from a cache. * * @param string $mapperID * @param string $mapperName * @param string $configFile * @return string * @throws PIECE_ORM_ERROR_CANNOT_READ * @throws PIECE_ORM_ERROR_CANNOT_WRITE */ function _getMapperSource($mapperID, $mapperName, $configFile) { $cache =& new Cache_Lite_File(array('cacheDir' => "{$GLOBALS['PIECE_ORM_Mapper_CacheDirectory']}/", 'masterFile' => $configFile, 'automaticSerialization' => true, 'errorHandlingAPIBreak' => true)); if (!Piece_ORM_Env::isProduction()) { $cache->remove($mapperID); } /* * The Cache_Lite class always specifies PEAR_ERROR_RETURN when * calling PEAR::raiseError in default. */ $mapperSource = $cache->get($mapperID); if (PEAR::isError($mapperSource)) { Piece_ORM_Error::push(PIECE_ORM_ERROR_CANNOT_READ, "Cannot read the mapper source file in the directory [ {$GLOBALS['PIECE_ORM_Mapper_CacheDirectory']} ]."); return; } if (!$mapperSource) { $mapperSource = Piece_ORM_Mapper_Factory::_generateMapperSource($mapperID, $mapperName, $configFile); if (Piece_ORM_Error::hasErrors()) { return; } $result = $cache->save($mapperSource); if (PEAR::isError($result)) { Piece_ORM_Error::push(PIECE_ORM_ERROR_CANNOT_WRITE, "Cannot write the mapper source to the cache file in the directory [ {$GLOBALS['PIECE_ORM_Mapper_CacheDirectory']} ]."); return; } } return $mapperSource; }
/** * Gets a Piece_ORM_Metadata object from a cache. * * @param string $tableName * @param string $tableID * @return Piece_ORM_Metadata */ function &_getMetadata($tableName, $tableID) { $cache =& new Cache_Lite(array('cacheDir' => "{$GLOBALS['PIECE_ORM_Metadata_CacheDirectory']}/", 'automaticSerialization' => true, 'errorHandlingAPIBreak' => true)); if (!Piece_ORM_Env::isProduction()) { $cache->remove($tableID); } /* * The Cache_Lite class always specifies PEAR_ERROR_RETURN when * calling PEAR::raiseError in default. */ $metadata = $cache->get($tableID); if (PEAR::isError($metadata)) { trigger_error("Cannot read the cache file in the directory [ {$GLOBALS['PIECE_ORM_Metadata_CacheDirectory']} ].", E_USER_WARNING); $metadata =& Piece_ORM_Metadata_Factory::_createMetadataFromDatabase($tableName); if (Piece_ORM_Error::hasErrors()) { $return = null; return $return; } return $metadata; } if (!$metadata) { $metadata =& Piece_ORM_Metadata_Factory::_createMetadataFromDatabase($tableName); if (Piece_ORM_Error::hasErrors()) { $return = null; return $return; } $result = $cache->save($metadata); if (PEAR::isError($result)) { trigger_error("Cannot write the Piece_ORM_Metadata object to the cache file in the directory [ {$GLOBALS['PIECE_ORM_Metadata_CacheDirectory']} ].", E_USER_WARNING); } } return $metadata; }