• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Zend/Cache.php

00001 <?php
00028 abstract class Zend_Cache
00029 {
00030 
00036     public static $standardFrontends = array('Core', 'Output', 'Class', 'File', 'Function', 'Page');
00037 
00043     public static $standardBackends = array('File', 'Sqlite', 'Memcached', 'Apc', 'ZendPlatform', 'Xcache', 'TwoLevels');
00044 
00050     public static $standardExtendedBackends = array('File', 'Apc', 'TwoLevels', 'Memcached', 'Sqlite');
00051 
00058     public static $availableFrontends = array('Core', 'Output', 'Class', 'File', 'Function', 'Page');
00059 
00066     public static $availableBackends = array('File', 'Sqlite', 'Memcached', 'Apc', 'ZendPlatform', 'Xcache', 'TwoLevels');
00067 
00071     const CLEANING_MODE_ALL              = 'all';
00072     const CLEANING_MODE_OLD              = 'old';
00073     const CLEANING_MODE_MATCHING_TAG     = 'matchingTag';
00074     const CLEANING_MODE_NOT_MATCHING_TAG = 'notMatchingTag';
00075     const CLEANING_MODE_MATCHING_ANY_TAG = 'matchingAnyTag';
00076 
00090     public static function factory($frontend, $backend, $frontendOptions = array(), $backendOptions = array(), $customFrontendNaming = false, $customBackendNaming = false, $autoload = false)
00091     {
00092         if (is_string($backend)) {
00093             $backendObject = self::_makeBackend($backend, $backendOptions, $customBackendNaming, $autoload);
00094         } else {
00095             if ((is_object($backend)) && (in_array('Zend_Cache_Backend_Interface', class_implements($backend)))) {
00096                 $backendObject = $backend;
00097             } else {
00098                 self::throwException('backend must be a backend name (string) or an object which implements Zend_Cache_Backend_Interface');
00099             }
00100         }
00101         if (is_string($frontend)) {
00102             $frontendObject = self::_makeFrontend($frontend, $frontendOptions, $customFrontendNaming, $autoload);
00103         } else {
00104             if (is_object($frontend)) {
00105                 $frontendObject = $frontend;
00106             } else {
00107                 self::throwException('frontend must be a frontend name (string) or an object');
00108             }
00109         }
00110         $frontendObject->setBackend($backendObject);
00111         return $frontendObject;
00112     }
00113 
00123     public static function _makeBackend($backend, $backendOptions, $customBackendNaming = false, $autoload = false)
00124     {
00125         if (!$customBackendNaming) {
00126             $backend  = self::_normalizeName($backend);
00127         }
00128         if (in_array($backend, Zend_Cache::$standardBackends)) {
00129             // we use a standard backend
00130             $backendClass = 'Zend_Cache_Backend_' . $backend;
00131             // security controls are explicit
00132             require_once str_replace('_', DIRECTORY_SEPARATOR, $backendClass) . '.php';
00133         } else {
00134             // we use a custom backend
00135             if (!preg_match('~^[\w]+$~D', $backend)) {
00136                 Zend_Cache::throwException("Invalid backend name [$backend]");
00137             }
00138             if (!$customBackendNaming) {
00139                 // we use this boolean to avoid an API break
00140                 $backendClass = 'Zend_Cache_Backend_' . $backend;
00141             } else {
00142                 $backendClass = $backend;
00143             }
00144             if (!$autoload) {
00145                 $file = str_replace('_', DIRECTORY_SEPARATOR, $backendClass) . '.php';
00146                 if (!(self::_isReadable($file))) {
00147                     self::throwException("file $file not found in include_path");
00148                 }
00149                 require_once $file;
00150             }
00151         }
00152         return new $backendClass($backendOptions);
00153     }
00154 
00164     public static function _makeFrontend($frontend, $frontendOptions = array(), $customFrontendNaming = false, $autoload = false)
00165     {
00166         if (!$customFrontendNaming) {
00167             $frontend = self::_normalizeName($frontend);
00168         }
00169         if (in_array($frontend, self::$standardFrontends)) {
00170             // we use a standard frontend
00171             // For perfs reasons, with frontend == 'Core', we can interact with the Core itself
00172             $frontendClass = 'Zend_Cache_' . ($frontend != 'Core' ? 'Frontend_' : '') . $frontend;
00173             // security controls are explicit
00174             require_once str_replace('_', DIRECTORY_SEPARATOR, $frontendClass) . '.php';
00175         } else {
00176             // we use a custom frontend
00177             if (!preg_match('~^[\w]+$~D', $frontend)) {
00178                 Zend_Cache::throwException("Invalid frontend name [$frontend]");
00179             }
00180             if (!$customFrontendNaming) {
00181                 // we use this boolean to avoid an API break
00182                 $frontendClass = 'Zend_Cache_Frontend_' . $frontend;
00183             } else {
00184                 $frontendClass = $frontend;
00185             }
00186             if (!$autoload) {
00187                 $file = str_replace('_', DIRECTORY_SEPARATOR, $frontendClass) . '.php';
00188                 if (!(self::_isReadable($file))) {
00189                     self::throwException("file $file not found in include_path");
00190                 }
00191                 require_once $file;
00192             }
00193         }
00194         return new $frontendClass($frontendOptions);
00195     }
00196 
00204     public static function throwException($msg)
00205     {
00206         // For perfs reasons, we use this dynamic inclusion
00207         require_once 'Zend/Cache/Exception.php';
00208         throw new Zend_Cache_Exception($msg);
00209     }
00210 
00217     protected static function _normalizeName($name)
00218     {
00219         $name = ucfirst(strtolower($name));
00220         $name = str_replace(array('-', '_', '.'), ' ', $name);
00221         $name = ucwords($name);
00222         $name = str_replace(' ', '', $name);
00223         return $name;
00224     }
00225 
00236     private static function _isReadable($filename)
00237     {
00238         if (!$fh = @fopen($filename, 'r', true)) {
00239             return false;
00240         }
00241         @fclose($fh);
00242         return true;
00243     }
00244 
00245 }

Generated on Thu Apr 19 2012 17:01:16 for openbiz by  doxygen 1.7.2