Esempio n. 1
0
 /**
  * Triggers an option event if this options instance has a connection to
  * an adapter implements EventsCapableInterface.
  *
  * @param string $optionName
  * @param mixed  $optionValue
  * @return void
  */
 protected function triggerOptionEvent($optionName, $optionValue)
 {
     if ($this->adapter instanceof EventsCapableInterface) {
         $event = new Event('option', $this->adapter, new ArrayObject([$optionName => $optionValue]));
         $this->adapter->getEventManager()->triggerEvent($event);
     }
 }
Esempio n. 2
0
 /**
  * Change a capability
  *
  * @param  stdClass $marker
  * @param  string $property
  * @param  mixed $value
  * @return Capabilities Fluent interface
  * @throws Exception\InvalidArgumentException
  */
 protected function setCapability(stdClass $marker, $property, $value)
 {
     if ($this->marker !== $marker) {
         throw new Exception\InvalidArgumentException('Invalid marker');
     }
     if ($this->{$property} !== $value) {
         $this->{$property} = $value;
         // trigger event
         if ($this->storage instanceof EventsCapableInterface) {
             $this->storage->getEventManager()->trigger('capability', $this->storage, new ArrayObject(array($property => $value)));
         }
     }
     return $this;
 }
Esempio n. 3
0
 /**
  * Fakes an exception in the cache, so that the cache's own EventManager decides what to do with it (throw or continue without cache)
  *
  * @param string $eventName name of faked storage adapter method (e.g. getItem or setItem)
  * @param array $args arguments for the faked method call to the storage adapter
  * @param mixed $result return value of the faked method call in case the exception will not be (re)thrown
  * @param \Exception $exception exception which 'supposedly' got thrown within the faked method
  * @return mixed the return value after triggering an ExceptionEvent at the EventManager (most likely the original $result)
  * @throws \Exception the original $exception, depending on the ExceptionEvent's 'ThrowException' value after being triggered at the EventManager
  * @see \Zend\Cache\Storage\Adapter\AbstractAdapter::triggerException()
  */
 protected static function triggerCacheException($eventName, $args, &$result, \Exception $exception)
 {
     if (is_null(self::$cache)) {
         return $result;
     }
     if (is_array($args)) {
         $args = new \ArrayObject($args);
     }
     $exceptionEvent = new \Zend\Cache\Storage\ExceptionEvent($eventName . '.exception', self::$cache, $args, $result, $exception);
     $responseCollection = self::$cache->getEventManager()->trigger($exceptionEvent);
     if ($exceptionEvent->getThrowException()) {
         throw $exceptionEvent->getException();
     }
     if ($responseCollection->stopped()) {
         return $responseCollection->last();
     }
     return $exceptionEvent->getResult();
 }