yohang / Finite

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

is it possible to undo transition? #58

Closed richhl closed 9 years ago

richhl commented 10 years ago

in case of a mistake this is important....for example one has approve an article by error and wants to return to previous state....

sagikazarmark commented 10 years ago

Since a state can have many transitions ("forward" or "backward") I think no. If you follow a linear pattern (so A -> B -> C and C -> B -> A, but no C -> A), then you might be able find some way. Hence the unlimited number of transitions between any states there is no such previous state, and IMO there won't be any.

matteosister commented 10 years ago

just implement the inverse transition. For example:

draft -> publish -> published published -> unpublish -> draft

It's up to you implementing the logic (for example managing the events) of the reverse transition.

yohang commented 9 years ago

It's up to you to define reverse transitions. Transitions should be associated to a "verb" like "publish", "propose", "accept", if needed, you can define reverse side, like "unpublish", "reject".