Пример #1
0
 /**
  * returns the associated Command for the entry/exit action.
  * the Command will be configured with the domain model via dependency injection
  *
  * @param string $command_name
  *            entry or exit command name
  * @param Context $context            
  * @return ICommand
  * @throws Exception
  */
 protected function getCommand($command_name, Context $context)
 {
     return Utils::getCommand($command_name, $context);
 }
 /**
  * Sets the new state for an Identifier in the storage facility.
  * Will only be called by the statemachine.
  * A template method.
  *
  * @param Identifier $identifier
  *            (old state can be retrieved via the identifier and this class)
  * @param string $state
  *            this is the new state
  * @param string $message optional message. this can be used by the persistence adapter
  *          to be part of the transition history to provide extra information about the transition.
  * @return boolan false if already stored before, true if just added
  * @throws Exception
  */
 public function setState(Identifier $identifier, $state, $message = null)
 {
     try {
         // a subclass could map a state to
         // something else that is used internally in legacy
         // systems (eg: order.order_status)
         return $this->processSetState($identifier, $state, $message);
     } catch (\Exception $e) {
         // a possible lowlevel nonstatemachine exception, wrap it and throw
         $e = Utils::wrapToStateMachineException($e, Exception::IO_FAILURE_SET);
         throw $e;
     }
 }
Пример #3
0
 /**
  * @test
  * @group regex
  */
 public function shouldReturnArrayOfMatchedStates()
 {
     $a = new State('a');
     $b = new State('ab');
     $c = new State('ba');
     $d = new State('abracadabra');
     $e = new State('action-hero');
     $f = new State('action-bad-guy');
     $g = new State('ac');
     $targets = array($a, $b, $c, $d, $e, $f, $g);
     $regex = new State('regex:/.*/');
     $this->assertEquals($targets, Utils::getAllRegexMatchingStates($regex, $targets));
     $regex = new State('regex:/^a.*/');
     $this->assertEquals(array($a, $b, $d, $e, $f, $g), Utils::getAllRegexMatchingStates($regex, $targets));
     $regex = new State('regex:/^a.+/');
     $this->assertEquals(array($b, $d, $e, $f, $g), Utils::getAllRegexMatchingStates($regex, $targets));
     $regex = new State('regex:/^a.*a.+$/');
     $this->assertEquals(array($d, $f), Utils::getAllRegexMatchingStates($regex, $targets));
     $regex = new State('regex:/^ac.*-.+$/');
     $this->assertEquals(array($e, $f), Utils::getAllRegexMatchingStates($regex, $targets));
     $regex = new State('ac');
     $this->assertFalse($regex->isRegex());
     $this->assertEquals(array($g), Utils::getAllRegexMatchingStates($regex, $targets), 'non regex state');
 }
 /**
  * Always throws an izzum exception (converts a non-izzum exception to an
  * izzum exception)
  *
  * @param \Exception $e            
  * @param int $code
  *            if the exception is not of type Exception, wrap it and use
  *            this code.
  * @param Transition $transition
  *            optional. if set, we handle it as a transition exception too
  *            so it can be logged or handled
  * @throws Exception an izzum exception
  */
 protected function handlePossibleNonStatemachineException(\Exception $e, $code, $transition = null)
 {
     $e = Utils::wrapToStateMachineException($e, $code);
     if ($transition !== null) {
         $this->handleTransitionException($transition, $e);
     }
     throw $e;
 }
 /**
  * get the transition name.
  * the transition name is always unique for a statemachine
  * since it constists of <state_from>_to_<state_to>
  *
  * @return string
  */
 public function getName()
 {
     $name = Utils::getTransitionName($this->getStateFrom()->getName(), $this->getStateTo()->getName());
     return $name;
 }