Exemplo n.º 1
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->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 . '"');
         }
     }
 }
Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 3
0
 /**
  * @param TransitionInterface $transition
  *
  * @return string
  */
 protected function getTransitionLabel(StateInterface $state, TransitionInterface $transition)
 {
     $labelParts = array();
     $eventName = $transition->getEventName();
     if ($eventName) {
         $labelParts[] = 'E: ' . $eventName;
         $event = $state->getEvent($eventName);
         $observerName = $this->convertObserverToString($event);
         if ($observerName) {
             $labelParts[] = 'C: ' . $observerName;
         }
     }
     $conditionName = $transition->getConditionName();
     if ($conditionName) {
         $labelParts[] = 'IF: ' . $conditionName;
     }
     if ($transition instanceof WeightedInterface) {
         $labelParts[] = 'W: ' . $transition->getWeight();
     }
     $label = implode(PHP_EOL, $labelParts);
     return $label;
 }
Exemplo n.º 4
0
 /**
  * @param StateInterface     $sourceState
  * @param string             $eventName
  *
  * @return EventInterface
  */
 public function createEvent(StateInterface $sourceState, $eventName)
 {
     if ($sourceState instanceof State) {
         return $sourceState->getEvent($eventName);
     } else {
         throw new \InvalidArgumentException('Overwrite this method to implement a different type!');
     }
 }
Exemplo n.º 5
0
 /**
  * @param  TransitionInterface $transition
  * @return string
  */
 protected function getTransitionLabel(StateInterface $state, TransitionInterface $transition)
 {
     $labelParts = array();
     $eventName = $transition->getEventName();
     if ($eventName) {
         $labelParts[] = 'E: ' . $eventName;
         $event = $state->getEvent($eventName);
         $observers = $event->getObservers();
         $observerName = implode(', ', iterator_to_array($observers, false));
         if ($observerName) {
             $labelParts[] = 'C: ' . $observerName;
         }
     }
     $conditionName = $transition->getConditionName();
     if ($conditionName) {
         $labelParts[] = 'IF: ' . $conditionName;
     }
     $label = implode(PHP_EOL, $labelParts);
     return $label;
 }