src/TransitionCapableStateMachineTrait.php
protected function _transition(StateAwareInterface $subject, $transition)
    {
        // Retrieve the state machine to use
        $stateMachine = $this->_getStateMachineForTransition($subject, $transition);
        // Ensure it is not null
        if ($stateMachine === null) {
            throw $this->_throwTransitionerException($this->__('State machine is null'));
        }

        // Normalize the transition before using it in the state machine
        $nTransition = $this->_normalizeTransition($subject, $transition);

        try {
            // Attempt to transition using the state machine
            $rStateMachine = $stateMachine->transition($nTransition);
        } catch (SmCouldNotTransitionExceptionInterface $smtException) {
            throw $this->_throwCouldNotTransitionException(
                $this->__('Failed to apply "%1$s" transition', [$transition]),
                null,
                $smtException,
                $subject,
                $transition
            );
        } catch (StateMachineExceptionInterface $smException) {
            throw $this->_throwTransitionerException(
                $this->__('An error occurred during transition'), null, $smException
            );
        }

        if (!($rStateMachine instanceof ReadableStateMachineInterface)) {
            throw $this->_throwTransitionerException(
                $this->__('Resulting state machine is not readable')
            );
        }

        // Determine the new subject from the input arguments and the retrieved state machine
        return $this->_getNewSubject($subject, $transition, $rStateMachine);
    }
protected function _transition(StateAwareInterface $subject, $transition)
    {
        // Retrieve the state machine to use
        $stateMachine = $this->_getStateMachineForTransition($subject, $transition);
        // Ensure it is not null
        if ($stateMachine === null) {
            throw $this->_throwTransitionerException($this->__('State machine is null'));
        }

        // Normalize the transition before using it in the state machine
        $nTransition = $this->_normalizeTransition($subject, $transition);

        try {
            // Attempt to transition using the state machine
            $rStateMachine = $stateMachine->transition($nTransition);
        } catch (SmCouldNotTransitionExceptionInterface $smtException) {
            throw $this->_throwCouldNotTransitionException(
                $this->__('Failed to apply "%1$s" transition', [$transition]),
                null,
                $smtException,
                $subject,
                $transition
            );
        } catch (StateMachineExceptionInterface $smException) {
            throw $this->_throwTransitionerException(
                $this->__('An error occurred during transition'), null, $smException
            );
        }

        if (!($rStateMachine instanceof ReadableStateMachineInterface)) {
            throw $this->_throwTransitionerException(
                $this->__('Resulting state machine is not readable')
            );
        }

        // Determine the new subject from the input arguments and the retrieved state machine
        return $this->_getNewSubject($subject, $transition, $rStateMachine);
    }
protected function _transition ( StateAwareInterface $ subject , $ transition ) { // Retrieve the state machine to use $ stateMachine = $ this -> _getStateMachineForTransition ( $ subject , $ transition ) ; // Ensure it is not null if ( $ stateMachine === null ) { throw $ this -> _throwTransitionerException ( $ this -> __ ( 'State machine is null' ) ) ; } // Normalize the transition before using it in the state machine $ nTransition = $ this -> _normalizeTransition ( $ subject , $ transition ) ; try { // Attempt to transition using the state machine $ rStateMachine = $ stateMachine -> transition ( $ nTransition ) ; } catch ( SmCouldNotTransitionExceptionInterface $ smtException ) { throw $ this -> _throwCouldNotTransitionException ( $ this -> __ ( 'Failed to apply "%1$s" transition' , [ $ transition ] ) , null , $ smtException , $ subject , $ transition ) ; } catch ( StateMachineExceptionInterface $ smException ) { throw $ this -> _throwTransitionerException ( $ this -> __ ( 'An error occurred during transition' ) , null , $ smException ) ; } if ( ! ( $ rStateMachine instanceof ReadableStateMachineInterface ) ) { throw $ this -> _throwTransitionerException ( $ this -> __ ( 'Resulting state machine is not readable' ) ) ; } // Determine the new subject from the input arguments and the retrieved state machine return $ this -> _getNewSubject ( $ subject , $ transition , $ rStateMachine ) ; }
Applies a transition to a subject via a state machine.

@since [*next-version*]

@param StateAwareInterface    $subject    The subject to transition.
@param string|Stringable|null $transition The transition to apply.

@return StateAwareInterface The transitioned subject. May or may not be the same instance as the first argument.
Applies a transition to a subject via a state machine .