00001 <?php 00025 require_once 'Zend/Loader.php'; 00026 00027 00034 class Zend_Translate { 00038 const AN_ARRAY = 'Array'; 00039 const AN_CSV = 'Csv'; 00040 const AN_GETTEXT = 'Gettext'; 00041 const AN_INI = 'Ini'; 00042 const AN_QT = 'Qt'; 00043 const AN_TBX = 'Tbx'; 00044 const AN_TMX = 'Tmx'; 00045 const AN_XLIFF = 'Xliff'; 00046 const AN_XMLTM = 'XmlTm'; 00047 00048 const LOCALE_DIRECTORY = 'directory'; 00049 const LOCALE_FILENAME = 'filename'; 00050 00056 private $_adapter; 00057 private static $_cache = null; 00058 00069 public function __construct($adapter, $data, $locale = null, array $options = array()) 00070 { 00071 $this->setAdapter($adapter, $data, $locale, $options); 00072 } 00073 00083 public function setAdapter($adapter, $data, $locale = null, array $options = array()) 00084 { 00085 if (Zend_Loader::isReadable('Zend/Translate/Adapter/' . ucfirst($adapter). '.php')) { 00086 $adapter = 'Zend_Translate_Adapter_' . ucfirst($adapter); 00087 } 00088 00089 if (!class_exists($adapter)) { 00090 Zend_Loader::loadClass($adapter); 00091 } 00092 00093 if (self::$_cache !== null) { 00094 call_user_func(array($adapter, 'setCache'), self::$_cache); 00095 } 00096 $this->_adapter = new $adapter($data, $locale, $options); 00097 if (!$this->_adapter instanceof Zend_Translate_Adapter) { 00098 require_once 'Zend/Translate/Exception.php'; 00099 throw new Zend_Translate_Exception("Adapter " . $adapter . " does not extend Zend_Translate_Adapter"); 00100 } 00101 } 00102 00108 public function getAdapter() 00109 { 00110 return $this->_adapter; 00111 } 00112 00118 public static function getCache() 00119 { 00120 return self::$_cache; 00121 } 00122 00129 public static function setCache(Zend_Cache_Core $cache) 00130 { 00131 self::$_cache = $cache; 00132 } 00133 00139 public static function hasCache() 00140 { 00141 if (self::$_cache !== null) { 00142 return true; 00143 } 00144 00145 return false; 00146 } 00147 00153 public static function removeCache() 00154 { 00155 self::$_cache = null; 00156 } 00157 00163 public static function clearCache() 00164 { 00165 self::$_cache->clean(); 00166 } 00167 00171 public function __call($method, array $options) 00172 { 00173 if (method_exists($this->_adapter, $method)) { 00174 return call_user_func_array(array($this->_adapter, $method), $options); 00175 } 00176 require_once 'Zend/Translate/Exception.php'; 00177 throw new Zend_Translate_Exception("Unknown method '" . $method . "' called!"); 00178 } 00179 }