/**
  * @param DispatcherInterface $dispatcher
  * @param string              $name
  * @param \ArrayAccess        $context
  *
  * @throws \RuntimeException
  */
 public function dispatchEvent(DispatcherInterface $dispatcher, $name, \ArrayAccess $context = null)
 {
     if ($this->dispatcher) {
         throw new \RuntimeException('Event dispatching is still running!');
     } else {
         if ($this->currentState->hasEvent($name)) {
             $this->dispatcher = $dispatcher;
             if ($context) {
                 $this->currentContext = $context;
             } else {
                 $this->currentContext = new \ArrayIterator(array());
             }
             $this->currentEvent = $this->currentState->getEvent($name);
             $dispatcher->dispatch($this->currentEvent, array($this->subject, $this->currentContext), new Callback(array($this, 'onDispatcherReady')));
         } else {
             throw new \RuntimeException('Current state "' . $this->currentState->getName() . '" did not have event "' . $name . '"');
         }
     }
 }
Beispiel #2
0
 /**
  * @param DispatcherInterface $dispatcher
  * @param string              $name
  * @param \ArrayAccess        $context
  *
  * @throws \RuntimeException
  */
 public function dispatchEvent(DispatcherInterface $dispatcher, $name, \ArrayAccess $context = null)
 {
     if ($this->dispatcher) {
         throw new \RuntimeException('Event dispatching is still running!');
     } else {
         if ($this->currentState->hasEvent($name)) {
             $this->acquireLockOrThrowException();
             $this->dispatcher = $dispatcher;
             if ($context) {
                 $this->currentContext = $context;
             } else {
                 $this->currentContext = new \ArrayIterator(array());
             }
             $this->currentEvent = $this->currentState->getEvent($name);
             $dispatcher->dispatch($this->currentEvent, array($this->subject, $this->currentContext), new Callback(array($this, 'onDispatcherReady')));
         } else {
             throw new WrongEventForStateException($this->currentState->getName(), $name);
         }
     }
 }