sebdesign / laravel-state-machine

Winzou State Machine service provider for Laravel
MIT License
327 stars 57 forks source link

SMException when version is higher than 1.3.3 #26

Closed G89Angel closed 5 years ago

G89Angel commented 5 years ago

Hello,

whenever I use a version higher than 1.3.3 I get this exception:

SM\SMException - "Cannot set the state to "3" to object "App\Models\Order" with graph graphOrder because it is not pre-defined."

There is no change in state-machine and state 3 is listed in 'states'

'states' => [
            OrderState::E_OPEN,
            OrderState::E_RESERVED,
            OrderState::E_PAY_PROCESS, <-- 
            OrderState::E_ABANDONED,
            OrderState::E_CLOSED,
            OrderState::E_CANCELLED,
            OrderState::E_REFUND_PROCESS,
            OrderState::E_CANCELLATION_COMPLETED,
        ],

Everything is a scalar value resolved by a constant. I couldn't find anything in 1.4.4 commits that could give me a hint of what is going on

Any idea?

G89Angel commented 5 years ago

Nevermind, I didn't notice that states was now an array with a name param. Now it's working:

'states' => [
    [
        'name' => OrderState::E_OPEN,
        ...
    ]
],
sebdesign commented 5 years ago

Hello,

I'm sorry for the confusion, I think this is actually a bug, because internally it's converting the array of states to an array of arrays with name parameter. But it's not working for states that are numeric, only strings. I will make a PR to fix this.

Can you update to ^2.0 or are you using and older version of PHP / Laravel?

sebdesign commented 5 years ago

Fixed by 4ea333dac9236ba1fd49fa97ddc50c389412a513. Please upgrade to v2.0.2 or let me know if you need a 1.3.x release.

G89Angel commented 5 years ago

Perfect, I've been able to test it today and working perfectly as expected. Again, thank you very much.