Ejemplo n.º 1
0
 /**
  * Returns the page item cache.
  *
  * @return array
  */
 public function getPageItemCache()
 {
     $data = array();
     if ($this->_cacheEnabled()) {
         foreach (self::$_cache->getIdsMatchingTags(array($this->_getCacheInternalId())) as $id) {
             if (preg_match('|' . self::CACHE_TAG_PREFIX . "(\\d+)_.*|", $id, $page)) {
                 $data[$page[1]] = self::$_cache->load($this->_getCacheId($page[1]));
             }
         }
     }
     return $data;
 }
Ejemplo n.º 2
0
Archivo: File.php Proyecto: rexmac/zf2
 /**
  * Test if a cache is available for the given id and (if yes) return it (false else)
  *
  * @param  string  $id                     Cache id
  * @param  boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
  * @param  boolean $doNotUnserialize       Do not serialize (even if automatic_serialization is true) => for internal use
  * @return mixed|false Cached datas
  */
 public function load($id, $doNotTestCacheValidity = false, $doNotUnserialize = false)
 {
     if (!$doNotTestCacheValidity) {
         if ($this->test($id)) {
             return parent::load($id, true, $doNotUnserialize);
         }
         return false;
     }
     return parent::load($id, true, $doNotUnserialize);
 }
Ejemplo n.º 3
0
 /**
  * Initializes metadata.
  *
  * If metadata cannot be loaded from cache, adapter's describeTable() method is called to discover metadata
  * information. Returns true if and only if the metadata are loaded from cache.
  *
  * @return boolean
  * @throws \Zend\DB\Table\Exception
  */
 protected function _setupMetadata()
 {
     if ($this->metadataCacheInClass() && count($this->_metadata) > 0) {
         return true;
     }
     // Assume that metadata will be loaded from cache
     $isMetadataFromCache = true;
     // If $this has no metadata cache but the class has a default metadata cache
     if (null === $this->_metadataCache && null !== self::$_defaultMetadataCache) {
         // Make $this use the default metadata cache of the class
         $this->_setMetadataCache(self::$_defaultMetadataCache);
     }
     // If $this has a metadata cache
     if (null !== $this->_metadataCache) {
         // Define the cache identifier where the metadata are saved
         //get db configuration
         $dbConfig = $this->_db->getConfig();
         // Define the cache identifier where the metadata are saved
         $cacheId = md5((isset($dbConfig['options']['port']) ? ':' . $dbConfig['options']['port'] : null) . (isset($dbConfig['options']['host']) ? ':' . $dbConfig['options']['host'] : null) . '/' . $dbConfig['dbname'] . ':' . $this->_schema . '.' . $this->_name);
     }
     // If $this has no metadata cache or metadata cache misses
     if (null === $this->_metadataCache || !($metadata = $this->_metadataCache->load($cacheId))) {
         // Metadata are not loaded from cache
         $isMetadataFromCache = false;
         // Fetch metadata from the adapter's describeTable() method
         $metadata = $this->_db->describeTable($this->_name, $this->_schema);
         // If $this has a metadata cache, then cache the metadata
         if (null !== $this->_metadataCache && !$this->_metadataCache->save($metadata, $cacheId)) {
             trigger_error('Failed saving metadata to metadataCache', E_USER_NOTICE);
         }
     }
     // Assign the metadata to $this
     $this->_metadata = $metadata;
     // Return whether the metadata were loaded from cache
     return $isMetadataFromCache;
 }
Ejemplo n.º 4
0
Archivo: Adapter.php Proyecto: hjr3/zf2
 /**
  * Internal function for adding translation data
  *
  * It may be a new language or additional data for existing language
  * If $clear parameter is true, then translation data for specified
  * language is replaced and added otherwise
  *
  * @see    Zend_Locale
  * @param  array|string       $data    Translation data
  * @param  string|\Zend\Locale\Locale $locale  Locale/Language to add data for, identical with locale identifier,
  *                                     @see Zend_Locale for more information
  * @param  array              $options (optional) Option for this Adapter
  * @throws \Zend\Translator\Exception
  * @return \Zend\Translator\Adapter\Adapter Provides fluent interface
  */
 private function _addTranslationData($data, $locale, array $options = array())
 {
     if ($data instanceof Translator\Translator || $data instanceof Adapter) {
         $options['usetranslateadapter'] = true;
         if (!empty($locale)) {
             $data = $data->getMessages($locale);
         } else {
             $locales = $data->getList();
             foreach ($locales as $locale) {
                 $trans = $data->getMessages($locale);
                 $this->_addTranslationData($trans, $locale, $options);
             }
             return $this;
         }
     }
     try {
         $locale = Locale\Locale::findLocale($locale);
     } catch (Locale\Exception $e) {
         throw new Translator\Exception("The given Language '{$locale}' does not exist", 0, $e);
     }
     if ($options['clear'] || !isset($this->_translate[$locale])) {
         $this->_translate[$locale] = array();
     }
     $read = true;
     if (isset(self::$_cache)) {
         $id = 'Zend_Translate_' . md5(serialize($data)) . '_' . $this->toString();
         $temp = self::$_cache->load($id);
         if ($temp) {
             $read = false;
         }
     }
     if ($options['reload']) {
         $read = true;
     }
     if ($read) {
         if (!empty($options['usetranslateadapter'])) {
             $temp = array($locale => $data);
         } else {
             $temp = $this->_loadTranslationData($data, $locale, $options);
         }
     }
     if (empty($temp)) {
         $temp = array();
     }
     $keys = array_keys($temp);
     foreach ($keys as $key) {
         if (!isset($this->_translate[$key])) {
             $this->_translate[$key] = array();
         }
         if (array_key_exists($key, $temp) && is_array($temp[$key])) {
             $this->_translate[$key] = $temp[$key] + $this->_translate[$key];
         }
     }
     if ($this->_automatic === true) {
         $find = new Locale\Locale($locale);
         $browser = $find->getEnvironment() + $find->getBrowser();
         arsort($browser);
         foreach ($browser as $language => $quality) {
             if (isset($this->_translate[$language])) {
                 $this->_options['locale'] = $language;
                 break;
             }
         }
     }
     if ($read and isset(self::$_cache)) {
         $id = 'Zend_Translate_' . md5(serialize($data)) . '_' . $this->toString();
         self::$_cache->save($temp, $id, array('Zend_Translate'));
     }
     return $this;
 }