yohang / Finite

A Simple PHP Finite State Machine

Home Page:http://yohan.giarel.li/Finite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Guards stopped working

Padam87 opened this issue · comments

f6b1886

This commit changed the way guards work. Now they can only stop a transition, but can't explicitly approve it like before. This is a huge BC break.

Previously if a guard returned true, the transition was good to go. Now it has to pass the regular checks too, and those will most likely fail.

There might be nothing to do about this now, but these changes should result in a major version bump in the future.

BC StateMachine for anyone looking

parameters:
    finite.state_machine.class: AppBundle\Finite\StateMachine
class StateMachine extends \Finite\StateMachine\StateMachine
{
    /**
     * {@inheritdoc}
     */
    public function can($transition, array $parameters = [])
    {
        $transition = $transition instanceof TransitionInterface ? $transition : $this->getTransition($transition);

        if ($transition->getGuard()) {
            return call_user_func($transition->getGuard(), $this);
        }

        return parent::can($transition, $parameters);
    }
}