Metabor\Statemachine\State::getEvent PHP Method

getEvent() public method

public getEvent ( $name )
    public function getEvent($name)
    {
        if ($this->events->has($name)) {
            $event = $this->events->get($name);
        } else {
            $event = new Event($name);
            $this->events->add($event);
        }
        return $event;
    }

Usage Example

 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);
 }
All Usage Examples Of Metabor\Statemachine\State::getEvent