setAdapter($adapter, $data, $locale, $options); } /** * Sets a new adapter * * @param string $adapter Adapter to use * @param string|array $data Translation data * @param string|Zend_Locale $locale OPTIONAL locale to use * @param array $options OPTIONAL Options to use * @throws Zend_Translate_Exception */ public function setAdapter($adapter, $data, $locale = null, array $options = array()) { if (Zend_Loader::isReadable('Zend/Translate/Adapter/' . ucfirst($adapter). '.php')) { $adapter = 'Zend_Translate_Adapter_' . ucfirst($adapter); } if (!class_exists($adapter)) { Zend_Loader::loadClass($adapter); } if (self::$_cache !== null) { call_user_func(array($adapter, 'setCache'), self::$_cache); } $this->_adapter = new $adapter($data, $locale, $options); if (!$this->_adapter instanceof Zend_Translate_Adapter) { require_once 'Zend/Translate/Exception.php'; throw new Zend_Translate_Exception("Adapter " . $adapter . " does not extend Zend_Translate_Adapter"); } } /** * Returns the adapters name and it's options * * @return Zend_Translate_Adapter */ public function getAdapter() { return $this->_adapter; } /** * Returns the set cache * * @return Zend_Cache_Core The set cache */ public static function getCache() { return self::$_cache; } /** * Sets a cache for all instances of Zend_Translate * * @param Zend_Cache_Core $cache Cache to store to * @return void */ public static function setCache(Zend_Cache_Core $cache) { self::$_cache = $cache; } /** * Returns true when a cache is set * * @return boolean */ public static function hasCache() { if (self::$_cache !== null) { return true; } return false; } /** * Removes any set cache * * @return void */ public static function removeCache() { self::$_cache = null; } /** * Clears all set cache data * * @return void */ public static function clearCache() { self::$_cache->clean(); } /** * Calls all methods from the adapter */ public function __call($method, array $options) { if (method_exists($this->_adapter, $method)) { return call_user_func_array(array($this->_adapter, $method), $options); } require_once 'Zend/Translate/Exception.php'; throw new Zend_Translate_Exception("Unknown method '" . $method . "' called!"); } }