/** * @param \SplSubject|StatemachineInterface|Statemachine $stateMachine * @return \ArrayAccess|null */ private function getStateMachineContext($stateMachine) { $context = null; if ($stateMachine instanceof Statemachine) { $context = $stateMachine->getCurrentContext(); } return $context; }
/** * * @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; }
/** * */ 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()); }
/** * @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; }