public function __construct() { $new = new State(self::STATE_NEW); $shipped = new State(self::STATE_SHIPPED); $dunning = new State(self::STATE_DUNNING); $paid = new State(self::STATE_PAID); $closed = new State(self::STATE_CLOSED); $returned = new State(self::STATE_RETURNED); $returnedAndClosed = new State(self::STATE_RETURNED_AND_CLOSED); $event = $new->getEvent(self::EVENT_SHIPPING); $command = function (EventInterface $event) { list($order, $context) = $event->getInvokeArgs(); echo 'Command: ' . $order . ' is shipped!' . PHP_EOL; }; $this->addCommand($event, $command); $shippingDateGreater14Days = new ShippingDateGreater14Days(); $new->addTransition(new Transition($shipped, self::EVENT_SHIPPING)); $shipped->addTransition(new Transition($dunning, null, $shippingDateGreater14Days)); $shipped->addTransition(new Transition($paid, self::EVENT_PAID)); $shipped->addTransition(new Transition($returnedAndClosed, self::EVENT_RETURNED)); $dunning->addTransition(new Transition($returnedAndClosed, self::EVENT_RETURNED)); $dunning->addTransition(new Transition($closed, self::EVENT_PAID)); $paid->addTransition(new Transition($closed, null, $shippingDateGreater14Days)); $paid->addTransition(new Transition($returned, self::EVENT_RETURNED)); $closed->addTransition(new Transition($returned, self::EVENT_RETURNED)); $returned->addTransition(new Transition($returnedAndClosed, self::EVENT_REFUND)); parent::__construct(self::PROCESS_POSTPAYMENT, $new); }
public function __construct() { $new = new State(self::STATE_NEW); $paymentFailed = new State(self::STATE_PAYMENT_FAILED); $paymentPending = new State(self::STATE_PAYMENT_PENDING); $shippable = new State(self::STATE_SHIPPABLE); $shipped = new State(self::STATE_SHIPPED); $closed = new State(self::STATE_CLOSED); $returned = new State(self::STATE_RETURNED); $returnedAndClosed = new State(self::STATE_RETURNED_AND_CLOSED); $event = $new->getEvent(self::EVENT_AUTHORIZE); $command = new Authorize(); $event->attach($command); $event = $shippable->getEvent(self::EVENT_SHIPPING); $command = function (EventInterface $event) { list($order, $context) = $event->getInvokeArgs(); echo 'Command: ' . $order . ' is shipped!' . PHP_EOL; }; $this->addCommand($event, $command); $shippingDateGreater14Days = new ShippingDateGreater14Days(); $authorizeSuccessful = new AuthorizedSuccessful(); $authorizeFailed = new Not($authorizeSuccessful); $new->addTransition(new Transition($paymentFailed, self::EVENT_AUTHORIZE, $authorizeFailed)); $new->addTransition(new Transition($paymentPending, self::EVENT_AUTHORIZE, $authorizeSuccessful)); $paymentPending->addTransition(new Transition($shippable, self::EVENT_PAID)); $shippable->addTransition(new Transition($shipped, self::EVENT_SHIPPING)); $shipped->addTransition(new Transition($closed, null, $shippingDateGreater14Days)); $shipped->addTransition(new Transition($returned, self::EVENT_RETURNED)); $closed->addTransition(new Transition($returned, self::EVENT_RETURNED)); $returned->addTransition(new Transition($returnedAndClosed, self::EVENT_REFUND)); parent::__construct(self::PROCESS_PREPAYMENT, $new); }
/** * @see \MetaborStd\Statemachine\StatemachineInterfaceTest::createTestInstance() */ protected function createTestInstance() { $subject = new \stdClass(); $subject->canBeClosed = false; $initialState = new State('new'); $transition = $this->getTransitionForTriggerTest(); $initialState->addTransition($transition); $transition->getTargetState()->addTransition($this->getTransitionForCheckTest()); $process = new Process('testProcess', $initialState); return new Statemachine($subject, $process); }