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

public addState ( MetaborStd\Statemachine\StateInterface $state )
$state MetaborStd\Statemachine\StateInterface
Пример #1
0
 /**
  * @param StateInterface $state
  */
 protected function addState(StateInterface $state)
 {
     $name = $state->getName();
     if ($this->states->hasState($name)) {
         if ($this->states->getState($name) !== $state) {
             throw new \Exception('There is already a different state with name "' . $name . '"');
         }
     } else {
         $this->states->addState($state);
         /* @var $transition TransitionInterface */
         foreach ($state->getTransitions() as $transition) {
             $targetState = $transition->getTargetState();
             $this->addState($targetState);
         }
     }
 }
 /**
  * @see \MetaborStd\NamedInterfaceTest::createTestInstance()
  */
 protected function createTestInstance()
 {
     $name = $this->getOneStateNameOfTheCollection();
     $state = new State($name);
     $instance = new StateCollection();
     $instance->addState($state);
     return $instance;
 }
 /**
  * @return \Metabor\Statemachine\StateCollection
  */
 protected function createSourceCollection()
 {
     $sourceCollection = new StateCollection();
     $stateNew = new State('new');
     $stateNew['test'] = true;
     $stateNew[self::FLAG_FOR_TEST] = self::FLAG_FOR_TEST_VALUE;
     $sourceCollection->addState($stateNew);
     $stateInProcess = new State('in progress');
     $sourceCollection->addState($stateInProcess);
     $stateDone = new State('done');
     $sourceCollection->addState($stateDone);
     $stateNew->addTransition(new Transition($stateInProcess, 'start'));
     $callback = new \Metabor\Callback\Callback($this);
     $observer = new Callback($callback);
     $event = $stateNew->getEvent('start');
     $event->attach($observer);
     $event['event flag'] = 'has command';
     $event[self::FLAG_FOR_TEST] = self::FLAG_FOR_TEST_VALUE;
     $stateInProcess->addTransition(new Transition($stateDone, null, new Tautology('is finished')));
     return $sourceCollection;
 }
Пример #4
0
 public function testAddsStatesToGraph()
 {
     $state = new State('first');
     $stateCollection = new StateCollection();
     $stateCollection->addState($state);
     $secondState = new State('second');
     $state->addTransition(new Transition($secondState));
     $graph = new Graph();
     $builder = new GraphBuilder($graph);
     $builder->addStateCollection($stateCollection);
     $this->assertTrue($graph->hasVertex('first'));
     $this->assertTrue($graph->hasVertex('second'));
 }