Exemple #1
0
 /**
  * Swap object data to disk
  * Actualy swaps data or only unloads it from memory,
  * if object is not changed since last swap
  *
  * @param \Zend\Memory\Container\Movable $container
  * @param integer $id
  */
 private function _swap(Container\Movable $container, $id)
 {
     if ($container->isLocked()) {
         return;
     }
     if (!$container->isSwapped()) {
         $this->_cache->save($container->getRef(), $this->_managerId . $id, $this->_tags);
     }
     $this->_memorySize -= $this->_sizes[$id];
     $container->markAsSwapped();
     $container->unloadValue();
 }
Exemple #2
0
 /**
  * Saves the given cache
  * Prevents broken cache when write_control is disabled and displays problems by log or error
  *
  * @param  mixed  $data
  * @param  string $id
  * @return boolean Returns false when the cache has not been written
  */
 protected function saveCache($data, $id)
 {
     if (self::$_cacheTags) {
         self::$_cache->save($data, $id, array($this->_options['tag']));
     } else {
         self::$_cache->save($data, $id);
     }
     if (!self::$_cache->test($id)) {
         if (!$this->_options['disableNotices']) {
             if ($this->_options['log']) {
                 $this->_options['log']->log("Writing to cache failed.", $this->_options['logPriority']);
             } else {
                 trigger_error("Writing to cache failed.", E_USER_NOTICE);
             }
         }
         self::$_cache->remove($id);
         return false;
     }
     return true;
 }
Exemple #3
0
 /**
  * Internal function for adding translation data
  *
  * This may be a new language or additional data for an existing language
  * If the options 'clear' is true, then the translation data for the specified
  * language is replaced and added otherwise
  *
  * @see    Zend_Locale
  * @param  array|Zend_Config $content Translation data to add
  * @throws Zend_Translate_Exception
  * @return Zend_Translate_Adapter Provides fluent interface
  */
 private function _addTranslationData($options = array())
 {
     if ($options instanceof \Zend\Config\Config) {
         $options = $options->toArray();
     } else {
         if (func_num_args() > 1) {
             $args = func_get_args();
             $options['content'] = array_shift($args);
             if (!empty($args)) {
                 $options['locale'] = array_shift($args);
             }
             if (!empty($args)) {
                 $options += array_shift($args);
             }
         }
     }
     if ($options['content'] instanceof Translator || $options['content'] instanceof Adapter) {
         $options['usetranslateadapter'] = true;
         if (!empty($options['locale']) && $options['locale'] !== 'auto') {
             $options['content'] = $options['content']->getMessages($options['locale']);
         } else {
             $content = $options['content'];
             $locales = $content->getList();
             foreach ($locales as $locale) {
                 $options['locale'] = $locale;
                 $options['content'] = $content->getMessages($locale);
                 $this->_addTranslationData($options);
             }
             return $this;
         }
     }
     try {
         $options['locale'] = Locale\Locale::findLocale($options['locale']);
     } catch (Locale\Exception $e) {
         throw new Exception("The given Language '{$locale}' does not exist", 0, $e);
     }
     if ($options['clear'] || !isset($this->_translate[$options['locale']])) {
         $this->_translate[$options['locale']] = array();
     }
     $read = true;
     if (isset(self::$_cache)) {
         $id = 'Zend_Translate_' . md5(serialize($options['content'])) . '_' . $this->toString();
         $temp = self::$_cache->load($id);
         if ($temp) {
             $read = false;
         }
     }
     if ($options['reload']) {
         $read = true;
     }
     if ($read) {
         if (!empty($options['usetranslateadapter'])) {
             $temp = array($options['locale'] => $options['content']);
         } else {
             $temp = $this->_loadTranslationData($options['content'], $options['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($options['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($options['content'])) . '_' . $this->toString();
         if (self::$_cacheTags) {
             self::$_cache->save($temp, $id, array($this->_options['tag']));
         } else {
             self::$_cache->save($temp, $id);
         }
     }
     return $this;
 }