Finite\StateMachine\StateMachine::apply PHP Method

apply() public method

public apply ( $transitionName, array $parameters = [] )
$parameters array
    public function apply($transitionName, array $parameters = array())
    {
        $transition = $this->getTransition($transitionName);
        $event = new TransitionEvent($this->getCurrentState(), $transition, $this, $parameters);
        if (!$this->can($transition, $parameters)) {
            throw new Exception\StateException(sprintf('The "%s" transition can not be applied to the "%s" state of object "%s" with graph "%s".', $transition->getName(), $this->currentState->getName(), get_class($this->getObject()), $this->getGraph()));
        }
        $this->dispatchTransitionEvent($transition, $event, FiniteEvents::PRE_TRANSITION);
        $returnValue = $transition->process($this);
        $this->stateAccessor->setState($this->object, $transition->getState());
        $this->currentState = $this->getState($transition->getState());
        $this->dispatchTransitionEvent($transition, $event, FiniteEvents::POST_TRANSITION);
        return $returnValue;
    }

Usage Example

Esempio n. 1
0
 /**
  * Transitions selected object
  *
  * @param \Illuminate\Database\Eloquent\Model $object
  * @param $value
  * @throws \Finite\Exception\StateException
  */
 public function apply(\Illuminate\Database\Eloquent\Model $object, $value, $properties = [])
 {
     $this->setStateMachine($object);
     $this->stateMachine->apply($value);
     $object->saveFiniteRelationship($this->stateMachine->getCurrentState()->getName(), $properties);
     event(new StateSuccessfullyApplied($object));
 }
All Usage Examples Of Finite\StateMachine\StateMachine::apply