Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to specify from/to arrays within transitions #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RobvH
Copy link

@RobvH RobvH commented Jan 16, 2017

Previously the state machine machine was able to express multiple source states for a transition, but was unable to define the complete source + transition = destination.
Consider processing + begin_checkpoint = checkpointing. However, for the begin_checkpoint transition a different destination state must be defined for another source state. E.g. shutting_down + begin_checkpoint = final_checkpointing, etc.

No backwards campatibilty issues, but now transitions can also look like this:

begin_checkpoint => [
    ['from' => ['shutting_down'], 'to'=>'final_checkpointing'], 
    ['from' => ['ready', 'processing'], 'to' => 'checkpointing']
],
begin_initialize => [
    'from' => ['start'],
    'to' => 'initializing'
]

Test added.
5.3 compatibilty maintained.

@RobvH RobvH force-pushed the State-plus-transition-keys-destination branch from 93d072b to f4d7719 Compare January 16, 2017 05:17
Previously the state machine machine was able to express multiple source states for a transition, but was unable to define the complete source + transition = destination.
Consider processing + begin_checkpoint = checkpointing. However, for the begin_checkpoint transition a different destination state must be defined for another source state. E.g. shutting_down + begin_checkpoint = final_checkpointing, etc.
No backwards campatibilty issues, but now transitions can also have begin_checkpoint => [['from' => ['shutting_down'], 'to'=>'final_checkpointing'], ['from' => ['ready', 'processing'], 'to' => 'checkpointing']]
Test added.
5.3 compatibilty maintained.
@RobvH RobvH force-pushed the State-plus-transition-keys-destination branch from f4d7719 to b39a265 Compare January 16, 2017 05:30
@semmel
Copy link

semmel commented Jul 1, 2017

Very useful for throwing events at a state machine. (I use it to manage via websocket connected clients when the connection opens/closes etc.)
👏
@winzou Please merge this PR, so nothing breaks with the next update when my local merge of @RobvH's changes might be overwritten.

@RobvH
Copy link
Author

RobvH commented Aug 17, 2017

@winzou Have you seen this PR? I would greatly appreciate any feedback you have.

@jorgens
Copy link

jorgens commented Sep 18, 2017

@winzou It would be great to have that feature for us as well. Any chance that this would be merged soon?

@RobvH
Copy link
Author

RobvH commented Feb 14, 2018

@winzou See you active about the repo now... It's been over a year without comment from you on a PR I expected would have been merged in a few hours. Do you have any questions or thoughts about this? I'm available to discuss or help out in any way possible.

@semmel
Copy link

semmel commented Feb 15, 2018

I still think this is a very useful addition and belongs in every state machine library. It seems it's just a patch not a big rewrite and so does not justify forking off the project and having the burden to maintain the fork afterwards. @winzou So please merge.

Though it won't benefit me any longer since I had the luxury to switch to Node.js for my websocket server. :-/

Copy link
Owner

@winzou winzou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So sorry guys for the delay, time goes so fast.
@RobvH can you just have a look at the review? Will merge soon after ;)

@@ -1,3 +1,4 @@
vendor
bin
composer.lock
.idea
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put it in your own .git/info/exclude file?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can... generally don't b/c some projects do check this in. 👍

$transition = $this->config['transitions']['create'];

$this->config['transitions']['create'] = array(
$transition
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you only test that an array of 1 transition works the same as before.
Could you add a test for the case where a transition name contains multiple transitions defined on different from states? So that we're sure that we call the right transition, depending on the current state.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 great catch, I absolutely will.

/**
* @param $transitionName
*
* @return bool|mixed
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null|array maybe?
It's more consistent to return null than false when there is no matching transition.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 agreed; it's more semantic this way. Thanks again. I'll include this in an update later today/tonight.

@RobvH
Copy link
Author

RobvH commented Feb 19, 2018

@winzou Will have a look during lunch break today! Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants