-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Workflow] added a TransitionsCollectionBuilder so DefinitionBuilder doesn't need Transition objects #20498
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
Conversation
What about supporting both ways (we would still need to think about good method names). That would not force the user to deconstruct already existing By the way, you also need to update the constructor's docblock. |
I'm not a fan of supporting both, but why not? I tend to prefer the BC break though, the commit has only three days and this is a lot nicer to me. I get used to not have any |
I was more thinking about use cases where you are reusing parts on an existing workflow definition. |
I understood #20451 was giving two possibilities. Either use one builder per definition, or keep using the same builder to add some transitions making the first a subset of the second. So I don't see the need to support what you're thinking about. |
If the definition wasn't build through the builder there is nothing you could based the next definition on (except we made it possible to initialise the builder with an existing definition). |
Ok got you, I'm going to fix this. Status: needs work. |
Status: needs review |
17c4169
to
99a8887
Compare
Can you make fabbot happy too? :) |
* @param string[] $places | ||
* @param Transition[] $transitions | ||
* @param string[] $places | ||
* @param (Transition|array)[] $transitions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this deserves some explanation about how such an array must be composed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this simply be @param Transition[] $transitions
?
@@ -79,15 +79,36 @@ public function addPlaces(array $places) | |||
} | |||
} | |||
|
|||
/** | |||
* @param (Transition|array)[] $transitions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
} | ||
} | ||
|
||
/** | ||
* @param Transition $transition |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed
} | ||
} | ||
|
||
/** | ||
* @param Transition $transition | ||
*/ | ||
public function addTransition(Transition $transition) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this method not support an array too?
* @param string[]|string $froms | ||
* @param string[]|string $tos | ||
*/ | ||
public function createTransition($name, $froms, $tos) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure this method belongs to the builder to be honest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the method name is misleading, because it does not only create the Transition (which would return it for usage) but instead it creates it internally and then adds it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok go for a polymorph addTransition
.
* @param string[]|string $froms | ||
* @param string[]|string $tos | ||
*/ | ||
public function createTransition($name, $froms, $tos) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the method name is misleading, because it does not only create the Transition (which would return it for usage) but instead it creates it internally and then adds it
array('t4', 'd', 'f'), | ||
array('t5', 'e', 'g'), | ||
array('t6', 'f', 'g'), | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why changing all these tests ? They are unrelated to your change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally removed the possibility to pass instances, and then I did not change back the tests because I found them much more readable like this, don't you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Na, I do not think it is more readable. Sorry =)
But it is a matter of taste.
58d4884
to
3562fad
Compare
Ok comments addressed here, thanks! |
3562fad
to
e70fdf3
Compare
e70fdf3
to
f900e2b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im not to sure this is needed. Is the argument only for convenience?
Anyhow, We need to validate the inputs properly so we do not cause any weird type errors.
array('t4', 'd', 'f'), | ||
array('t5', 'e', 'g'), | ||
array('t6', 'f', 'g'), | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Na, I do not think it is more readable. Sorry =)
But it is a matter of taste.
if ($transition instanceof Transition) { | ||
$this->transitions[] = $transition; | ||
} else { | ||
$this->transitions[] = new Transition($transition, $froms, $tos); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to validate the input here. What if some does:
$builder->addTransition('foo', 'bar');
if ($transition instanceof Transition) { | ||
$this->addTransition($transition); | ||
} else { | ||
list($name, $froms, $tos) = $transition; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to validate input. What if someone does:
$builder->addTransitions([['foo', 'bar']]);
// Or
$builder->addTransitions(['foo']);
Cant we introduce a |
And I think exactly the same as you ;)
|
But isn't this overkill just to avoid writing |
@HeahDude :)) but that affected direct user-land php configuration files, which made it considerable. And eventually the union type was avoided anyway (hence i think here it should also). In this case we could convert arrays to transition objects in the FrameworkExtension (using its own builder). |
Otherwise, maybe adding $builder->addTransition($builder->createTransition($array)); |
Sorry but I fail to understand why... $builder->addTransition($builder->createTransition($array))
// or
$builder->addTransition($builder->createTransition('foo', 'bar', 'baz')) ... is better/simpler/more convenient than: $builder->addTransition(new Transition(foo', 'bar', 'baz')); |
It's not. But it could be useful to have it when transforming configs into objects. |
You mean this line in FrameworkExtension would be: $transitions[] = array($transitionName, $from, $to); Is that the only win for this PR? |
Agree. I was already looking at it... this isnt actually needed to improve that. So, we have a definition builder for user-land, what about a transition builder as well? $t = (new TransitionBuilder())
->addTos($tos)
->addTo($to)
->build(); |
I've taking your comments into account already and started to work on it, I'm pushing it soon. |
Again, why is $t = (new TransitionBuilder())
->addTos($tos)
->addTo($to)
->build(); better/simpler than just: $t = new Transition(foo', 'bar', 'baz'); |
Again.. it's not :) guess it's matter of preference? Imo. it would be just as useful for having the Maybe we should re-consider that one first 😕 Ie. if we default the initial place to first available place directly in the As it was already removed from the framework extension for the same reason; overkill. Basically saying; it's practically not needed. |
Reading the comments, I agree that we should keep things simple. I still don't understand which problems this PR is trying to solve... but I do understand it adds complexity to the code. 👎 |
@Nyholm that's not what I've in mind, tests are failing, but I've pushed my concept. |
@fabpot I've just totally refactored it, one file to hold a new responsibility and a few lines changed. |
cf0c1b5
to
4814896
Compare
I still fail to understand the issue and why this is a better than what we have today. Can you explain? |
When using a But by introducing this transitions collection factory some tests are now failing because we use some definitions with invalid transitions and this actually looks like an issue IMHO. |
So, you're saying that it' better to use an abstraction and hide the |
25f7813
to
c8a5882
Compare
c8a5882
to
1530498
Compare
Ok then, closing here. Thanks everyone for the feedback. |
I am still not completely against this change, but I would rather provide two different methods. One were you pass a |
The more I think to this PR and to the DefinitionBuilder, the more I think the DefinitionBuilder is not really needed. It does not really help to reduce the number of LOC. Example: $transitions = [
new Transition('name', 'A', 'B'),
new Transition('name2', 'B', 'C'),
];
$definition = new Definition(['A', 'B', 'C'], $transitions);
(new DefinitionBuilder())
->addPlaces(['A', 'B', 'C'])
->addTransition(new Transition('name', 'A', 'B'))
->addTransition(new Transition('name2', 'B', 'C'))
; What do you think? Note: I'm agree with @fabpot about this PR and I'm also 👎 with its current state |
@lyrixx It's not about the LOC, it's about being able to add transitions without passing them to the constructor and keeping the |
I suggest to not construct
Transition
object repeatedly in user land code, ortherwise we can just create our ownDefinition
, let's abstract it in the builder.ping @lyrixx @Nyholm