Beispiel #1
0
 /**
  * Reads the specified item from the cache or generate it.
  * @param  mixed key
  * @param  callable
  * @return mixed|NULL
  */
 public function load($key, $fallback = NULL)
 {
     $data = $this->storage->read($this->generateKey($key));
     if ($data === NULL && $fallback) {
         return $this->save($key, new Nette\Callback($fallback));
     }
     return $data;
 }
Beispiel #2
0
 /**
  * Reads the specified item from the cache or generate it.
  * @param  mixed key
  * @param  callable
  * @return mixed|NULL
  */
 public function load($key, $fallback = NULL)
 {
     $data = $this->storage->read($this->namespace . md5(is_scalar($key) ? $key : serialize($key)));
     if ($data === NULL && $fallback) {
         return $this->save($key, callback($fallback));
     }
     return $data;
 }
Beispiel #3
0
 /**
  * Reads the specified item from the cache or generate it.
  * @param  mixed key
  * @param  callable
  * @return mixed|NULL
  */
 public function load($key, $fallback = NULL)
 {
     $data = $this->storage->read($this->generateKey($key));
     if ($data === NULL && $fallback) {
         return $this->save($key, function (&$dependencies) use($fallback) {
             return call_user_func_array($fallback, [&$dependencies]);
         });
     }
     return $data;
 }
Beispiel #4
0
 /**
  * Retrieves the specified item from the cache or returns NULL if the key is not found.
  * @param  mixed key
  * @return mixed|NULL
  */
 public function load($key)
 {
     $key = is_scalar($key) ? (string) $key : serialize($key);
     if ($this->key === $key) {
         return $this->data;
     }
     $this->key = $key;
     $this->data = $this->storage->read($this->namespace . md5($key));
     return $this->data;
 }
 /**
  * @param \l10n\Translator\Translator $translator
  */
 public function load(Translator $translator)
 {
     $language = $this->getLanguage();
     $data = $this->storage->read($language->getIso639_1()) ?: [];
     if ($data) {
         foreach ($data['untranslated'] ?: [] as $key => $texts) {
             foreach ($texts as $plural => $_) {
                 $translator->setUntranslated($key, $plural);
             }
         }
         foreach ($data['translated'] ?: [] as $key => $texts) {
             foreach ($texts as $plural => $text) {
                 $translator->setText($key, $text, $plural);
             }
         }
     }
 }