yohang / Finite

A Simple PHP Finite State Machine
http://yohan.giarel.li/Finite
MIT License
1.31k stars 188 forks source link

ArrayLoader Change to Use StateMachine's Accessor Breaks Existing State Machines #117

Open stephenjwinn opened 8 years ago

stephenjwinn commented 8 years ago

https://github.com/yohang/Finite/commit/c7a5672377695cdf65cd5f9a3372c18d0f02d7c1

The func hasStateAccessor() always evaluates to true because the StateMachine constructor inits the stateAccessor to a new PropertyPathStateAccessor...It's never null. So this doesn't work:

        if (!$stateMachine->hasStateAccessor()) {
           ** // I AM NEVER GOING TO LAND HERE.**
            $stateMachine->setStateAccessor(new PropertyPathStateAccessor($this->config['property_path']));
        }

This wouldn't be a problem, except the StateMachine constructor doesn't pass in a configuration property_path param to the PropertyPathStateAccessor. So the StateAccessor I have is not good. It doesn't ever grab the state.

    public function __construct(
        $object = null,
        EventDispatcherInterface $dispatcher = null,
        StateAccessorInterface $stateAccessor = null
    ) {
        $this->object = $object;
        $this->dispatcher = $dispatcher ?: new EventDispatcher();
        $this->stateAccessor = $stateAccessor ?: new PropertyPathStateAccessor();
    }
realshadow commented 8 years ago

Changing stateAccessor in constructor to $this->stateAccessor = $stateAccessor; should propably fix the issue unless there is some reason for initialization in constructor that I am not aware of.

I will look into it in the morning

realshadow commented 8 years ago

@stephenjwinn Please see #118