Author: Oliver Tischlinger
Inheritance: extends Metabor\Observer\Subject, implements MetaborStd\Statemachine\StatemachineInterface
コード例 #1
0
 /**
  * @param \SplSubject|StatemachineInterface|Statemachine $stateMachine
  * @return \ArrayAccess|null
  */
 private function getStateMachineContext($stateMachine)
 {
     $context = null;
     if ($stateMachine instanceof Statemachine) {
         $context = $stateMachine->getCurrentContext();
     }
     return $context;
 }
コード例 #2
0
 /**
  *
  * @param  object                                         $subject
  * @return \MetaborStd\Statemachine\StatemachineInterface
  */
 public function createStatemachine($subject)
 {
     $process = $this->processDetector->detectProcess($subject);
     if ($this->stateNameDetector) {
         $stateName = $this->stateNameDetector->detectCurrentStateName($subject);
         $statemachine = new Statemachine($subject, $process, $stateName, $this->transitonSelector);
     } else {
         $statemachine = new Statemachine($subject, $process, null, $this->transitonSelector);
     }
     foreach ($this->statemachineObserver as $observer) {
         $statemachine->attach($observer);
     }
     return $statemachine;
 }
コード例 #3
0
 /**
  *
  */
 public function testTriggerEventIfStatusIsChangedAndNewStateHasRegisteredEvent()
 {
     $process = new Process('process_name', new State('initinal'));
     $collection = new StateCollection();
     $helper = new SetupHelper($collection);
     $helper->findOrCreateTransition('initinal', 'second', 'go');
     $helper->findOrCreateTransition('second', 'error', 'error');
     $eventName = 'eventName';
     $helper->findOrCreateTransition('second', 'final', $eventName);
     $process->merge($collection);
     $subject = new \stdClass();
     $statemachine = new Statemachine($subject, $process);
     $statemachine->attach(new OnEnterObserver($eventName));
     $statemachine->triggerEvent('go');
     $this->assertEquals($process->getState('final'), $statemachine->getCurrentState());
 }
コード例 #4
0
ファイル: Factory.php プロジェクト: metabor/statemachine
 /**
  * @param object $subject
  *
  * @return \MetaborStd\Statemachine\StatemachineInterface
  */
 public function createStatemachine($subject)
 {
     $process = $this->processDetector->detectProcess($subject);
     if ($this->stateNameDetector) {
         $stateName = $this->stateNameDetector->detectCurrentStateName($subject);
     } else {
         $stateName = null;
     }
     if ($this->mutexFactory) {
         $mutex = $this->mutexFactory->createMutex($subject);
     } else {
         $mutex = null;
     }
     $statemachine = new Statemachine($subject, $process, $stateName, $this->transitonSelector, $mutex);
     foreach ($this->statemachineObserver as $observer) {
         $statemachine->attach($observer);
     }
     return $statemachine;
 }