/** * {@inheritdoc} */ protected function setUp() { $this->stateMachineBuilder = new StateMachineBuilder('Registration'); $this->stateMachineBuilder->addState('Input'); $this->stateMachineBuilder->addState('Confirmation'); $this->stateMachineBuilder->addState('Success'); $this->stateMachineBuilder->addState('Validation'); $this->stateMachineBuilder->addState('Registration'); $this->stateMachineBuilder->setStartState('Input', array($this, 'logActionCall')); $this->stateMachineBuilder->addTransition('Input', 'next', 'Validation', array($this, 'logActionCall')); $this->stateMachineBuilder->addTransition('Validation', 'valid', 'Confirmation', array($this, 'logActionCall')); $this->stateMachineBuilder->addTransition('Validation', 'invalid', 'Input', array($this, 'logActionCall')); $this->stateMachineBuilder->addTransition('Confirmation', 'next', 'Registration', array($this, 'logActionCall')); $this->stateMachineBuilder->addTransition('Confirmation', 'prev', 'Input', array($this, 'logActionCall')); $this->stateMachineBuilder->addTransition('Registration', 'next', 'Success', array($this, 'logActionCall')); $this->stateMachineBuilder->setEndState('Success', 'next', array($this, 'logActionCall')); $this->stateMachineBuilder->setEntryAction('Input', array($this, 'logActionCall')); $this->stateMachineBuilder->setActivity('Input', array($this, 'logActionCall')); $this->stateMachineBuilder->setExitAction('Input', array($this, 'logActionCall')); $this->stateMachineBuilder->setEntryAction('Confirmation', array($this, 'logActionCall')); $this->stateMachineBuilder->setActivity('Confirmation', array($this, 'logActionCall')); $this->stateMachineBuilder->setExitAction('Confirmation', array($this, 'logActionCall')); $this->stateMachineBuilder->setEntryAction('Success', array($this, 'logActionCall')); $this->stateMachineBuilder->setActivity('Success', array($this, 'logActionCall')); $this->stateMachineBuilder->setExitAction('Success', array($this, 'logActionCall')); $this->stateMachineBuilder->setEntryAction('Validation', array($this, 'logActionCall')); $this->stateMachineBuilder->setActivity('Validation', array($this, 'logActionCall')); $this->stateMachineBuilder->setExitAction('Validation', array($this, 'logActionCall')); $this->stateMachineBuilder->setEntryAction('Registration', array($this, 'logActionCall')); $this->stateMachineBuilder->setActivity('Registration', array($this, 'logActionCall')); $this->stateMachineBuilder->setExitAction('Registration', array($this, 'logActionCall')); }
/** * @return StateMachineInterface */ public function build() { $stateMachineBuilder = new StateMachineBuilder('registration'); $stateMachineBuilder->addState('input'); $stateMachineBuilder->addState('confirmation'); $stateMachineBuilder->addState('success'); $stateMachineBuilder->setStartState('input'); $stateMachineBuilder->addTransition('input', 'confirmation', 'confirmation'); $stateMachineBuilder->addTransition('confirmation', 'success', 'success'); $stateMachineBuilder->addTransition('confirmation', 'input', 'input'); $stateMachineBuilder->setEndState('success', StateInterface::STATE_FINAL); return $stateMachineBuilder->getStateMachine(); }
/** * Configures a PageFlow object from the specified definition. * * @return \Piece\Flow\PageFlow\PageFlowInterface * @throws \Piece\Flow\PageFlow\ProtectedStateException */ public function generate() { $definition = $this->readDefinition(); if (in_array($definition['firstState'], array(StateInterface::STATE_INITIAL, StateInterface::STATE_FINAL))) { throw new ProtectedStateException("The state [ {$definition['firstState']} ] cannot be used in flow definitions."); } foreach ($definition['viewState'] as $state) { if (in_array($state['name'], array(StateInterface::STATE_INITIAL, StateInterface::STATE_FINAL))) { throw new ProtectedStateException("The state [ {$state['name']} ] cannot be used in flow definitions."); } $this->addState(new ViewState($state['name'])); } foreach ($definition['actionState'] as $state) { if (in_array($state['name'], array(StateInterface::STATE_INITIAL, StateInterface::STATE_FINAL))) { throw new ProtectedStateException("The state [ {$state['name']} ] cannot be used in flow definitions."); } $this->addState(new ActionState($state['name'])); } if (!empty($definition['lastState'])) { if (in_array($definition['lastState']['name'], array(StateInterface::STATE_INITIAL, StateInterface::STATE_FINAL))) { throw new ProtectedStateException("The state [ {$definition['lastState']['name']} ] cannot be used in flow definitions."); } $this->addState(new ViewState($definition['lastState']['name'])); } if (empty($definition['initial'])) { $this->stateMachineBuilder->setStartState($definition['firstState']); } else { $this->stateMachineBuilder->setStartState($definition['firstState'], $this->wrapAction($definition['initial'])); } if (!empty($definition['lastState'])) { if (empty($definition['final'])) { $this->stateMachineBuilder->setEndState($definition['lastState']['name'], PageFlowInterface::EVENT_END); } else { $this->stateMachineBuilder->setEndState($definition['lastState']['name'], PageFlowInterface::EVENT_END, $this->wrapAction($definition['final'])); } $this->configureViewState($definition['lastState']); $this->stateMachineBuilder->getStateMachine()->getState($definition['lastState']['name'])->setView($definition['lastState']['view']); } $this->configureViewStates($definition['viewState']); $this->configureActionStates($definition['actionState']); return $this->pageFlow; }