Esempio n. 1
0
 /**
  * {@inheritDoc}
  */
 public function __invoke(CachePoolInterface $cache, $stage, CacheItemInterface $item = null)
 {
     if ($item instanceof CacheItemInterface) {
         if ($stage === ExtensionStage::STAGE_POST_GET) {
             if ($item->isHit()) {
                 $res = @unserialize($item->get());
             }
         } else {
             $res = @serialize($item->get());
         }
         if (isset($res)) {
             if ($res === false) {
                 return $this->falseAndSetError(Message::get(Message::CACHE_FAIL_SERIALIZE, $item->getKey()), Message::CACHE_FAIL_SERIALIZE);
             }
             $item->set($res);
         }
     }
     return true;
 }
Esempio n. 2
0
 /**
  * {@inheritDoc}
  */
 public function __invoke(CachePoolInterface $cache, $stage, CacheItemInterface $item = null)
 {
     if ($item instanceof CacheItemInterface) {
         if ($stage === ExtensionStage::STAGE_POST_GET) {
             if ($item->isHit()) {
                 $fnc = $this->decrypt;
                 $res = $fnc($item->get());
             }
         } else {
             $fnc = $this->encrypt;
             $res = $fnc($item->get());
         }
         if (isset($res)) {
             // encrypt/decrypt failed
             if ($res === false) {
                 return $this->falseAndSetError(Message::get(Message::CACHE_FAIL_ENCRYPT, $item->getKey()), Message::CACHE_FAIL_ENCRYPT);
             }
             // set to new string value
             $item->set($res);
         }
     }
     return true;
 }