-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
[Workflow] Clarify validator API + fixed unknown "scalar" marking store #20492
Conversation
I agree that it is not really intuitive to throw an exception in case of an invalid definition, but return |
@@ -23,7 +23,7 @@ | |||
* @param Definition $definition | |||
* @param string $name | |||
* | |||
* @return bool | |||
* @return void |
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.
should be removed entirely
So.. what about removing the Looks like a premature optimization to me.. and im not even sure validators should resemble a semi same inheritance tree. |
Back to 1 workflow validator and 1 state machine validator seems most intuitive to me =/ |
You should not validate every workflows as a single place workflow, this feels wrong to me. |
Not sure i understand.. right now it's optin. |
Ok haven't look at the code yet :p |
@@ -59,19 +58,24 @@ private function getValidator($tag) | |||
{ | |||
if ($tag['type'] === 'state_machine') { |
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.
Please use yoda condition
@@ -59,19 +58,24 @@ private function getValidator($tag) | |||
{ | |||
if ($tag['type'] === 'state_machine') { | |||
$name = 'state_machine'; | |||
$class = StateMachineValidator::class; | |||
} elseif ($tag['marking_store'] === 'scalar') { |
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.
single_state
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.
That would be a bug fix right?
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.
Needed since 08464c9
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.
As you're already at bug fixing :)
} elseif ($tag['marking_store'] === 'scalar') { | ||
$name = 'single_place'; | ||
$class = SinglePlaceWorkflowValidator::class; | ||
$name = 'workflow_single_place'; |
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.
You should rename this workflow_single_state
for consistency
foreach ($definition->getTransitions() as $transition) { | ||
if (1 < count($transition->getTos())) { | ||
throw new InvalidDefinitionException( | ||
sprintf( |
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.
Should be inlined
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.
public function validate(Definition $definition, $name) | ||
{ | ||
if ($this->singlePlace) { | ||
foreach ($definition->getTransitions() as $transition) { | ||
if (1 < count($transition->getTos())) { |
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.
If (count($transition->getTos()) > 1)
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.
This was, as is, accepted before (and is actually yoda style). Not sure we should change it now..
} | ||
|
||
return $this->validators[$name]; | ||
switch ($name) { |
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.
It's a bit cumbersome to have a if / else
then the same switch
And IMHO, we could remove the cache layer to make code simpler. it's a premature optimization that does not bring real perf improvement .
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.
One little comment, and after that I'm Ok with this PR.
👍 (I removed the Bug label, since it's not a bug. Could you edit your PR description?) |
if ($tag['type'] === 'state_machine') { | ||
$name = 'state_machine'; | ||
$class = StateMachineValidator::class; | ||
} elseif ($tag['marking_store'] === 'scalar') { |
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.
Actually this is a kind of bug :)
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?
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.
Missing from 08464c9.
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.
Updated PR description title.
Good catch, thanks @ro0NL. |
See also https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ValidateWorkflowsPass.php#L48