izzum\statemachine\Transition::process PHP Метод

process() публичный Метод

Process the transition for the statemachine and execute the associated Command with the domain object injected.
public process ( Context $context ) : void
$context Context
Результат void
    public function process(Context $context)
    {
        // execute, we do not need to check if we 'can' since this is done
        // by the statemachine itself
        try {
            $this->getCommand($context)->execute();
            $this->callCallable($this->getTransitionCallable(), $context, self::CALLABLE_TRANSITION);
        } catch (\Exception $e) {
            // command or callable failure
            $e = new Exception($e->getMessage(), Exception::COMMAND_EXECUTION_FAILURE, $e);
            throw $e;
        }
    }

Usage Example

 /**
  * @test
  */
 public function shouldThrowExceptionFromAppliedCommand()
 {
     $from = new State('a');
     $to = new State('b');
     $rule = 'izzum\\rules\\TrueRule';
     $command = 'izzum\\command\\ExceptionCommand';
     $object = new Context(new Identifier(Identifier::NULL_ENTITY_ID, Identifier::NULL_STATEMACHINE));
     $transition = new Transition($from, $to, null, $rule, $command);
     try {
         $transition->process($object);
         $this->fail('should not come here');
     } catch (Exception $e) {
         $this->assertEquals(Exception::COMMAND_EXECUTION_FAILURE, $e->getCode());
     }
     $this->assertTrue($transition->can($object));
 }