-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Workflow] Introduce a Workflow interface #24751
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] Introduce a Workflow interface #24751
Conversation
df6cd73
to
4b25e0d
Compare
Note that changing a public interface is a BC break, so this cannot be merged as is, isn't it? |
@nicolas-grekas the upgrade note is misleading, this replaces the whole interface. |
I guess i have to update the upgrade node
|
347c55e
to
a673253
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.
Some minor comments, but it's good.
Thanks.
UPGRADE-4.0.md
Outdated
|
||
* Deprecated the `add` method in favor of the `addWorkflow` method in `Workflow\Registry` | ||
* Deprecated the interface `SupportStrategyInterface` in favor of the interface `SupportStrategryWorkflowInterface` | ||
|
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.
Looks like there is a space here
@@ -5,6 +5,9 @@ CHANGELOG | |||
----- | |||
|
|||
* Removed class name support in `WorkflowRegistry::add()` as second parameter. | |||
* Deprecate the usage of `add(Workflow $workflow, $supportStrategy) in `Workflow/Registry` use `addWorkflow(WorkflowInterface, $supportStrategy)` instead |
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 backquote at the end of add(Workflow $workflow, $supportStrategy)
@@ -28,8 +29,17 @@ class Registry | |||
*/ | |||
public function add(Workflow $workflow, $supportStrategy) | |||
{ | |||
if (!$supportStrategy instanceof SupportStrategyInterface) { | |||
throw new \InvalidArgumentException('The "supportStrategy" is not an instance of SupportStrategyInterface.'); | |||
@trigger_error('add is deprecated since Symfony 4.0. Use addWorkflow instead', E_USER_DEPRECATED); |
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.
'add' method is ... use 'addWorkflow' insteand.
(don't miss the final dot)
public function addWorkflow(WorkflowInterface $workflow, $supportStrategy) | ||
{ | ||
if ($supportStrategy instanceof SupportStrategyInterface) { | ||
@trigger_error('Passing a SupportStrategyInterface in Registry::addWorkflow is deprecated since 4.0. Use SupportStrategyWorkflowInterface instead', E_USER_DEPRECATED); |
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.
use quote to surround class name and add a final dot.
if ($supportStrategy instanceof SupportStrategyInterface) { | ||
@trigger_error('Passing a SupportStrategyInterface in Registry::addWorkflow is deprecated since 4.0. Use SupportStrategyWorkflowInterface instead', E_USER_DEPRECATED); | ||
} | ||
if (!($supportStrategy instanceof SupportStrategyWorkflowInterface || $supportStrategy instanceof SupportStrategyInterface)) { |
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 if
could be transformed in an elseif (!$supportStrategy instanceof SupportStrategyWorkflowInterface)
@@ -11,6 +11,8 @@ | |||
|
|||
namespace Symfony\Component\Workflow\SupportStrategy; | |||
|
|||
@trigger_error('SupportStrategyInterface is deprecated since Symfony 4.0. Use SupportStrategyWorkflowInterface instead', E_USER_DEPRECATED); |
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 add a final dot
* | ||
* @return bool true if the transition is enabled | ||
*/ | ||
public function can($subject, $transitionName); |
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.
Hm, if getMarking can throw an exception, then can and apply may throw an exception too
a597789
to
f59403d
Compare
@lyrixx Thanks for the review :) |
UPGRADE-4.0.md
Outdated
@@ -913,7 +913,9 @@ Workflow | |||
-------- | |||
|
|||
* Removed class name support in `WorkflowRegistry::add()` as second parameter. | |||
|
|||
* Deprecated the `add` method in favor of the `addWorkflow` method in `Workflow\Registry` | |||
* Deprecated the interface `SupportStrategyInterface` in favor of the interface `SupportStrategryWorkflowInterface` |
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.
typo here (strategry)
f59403d
to
6902c37
Compare
UPGRADE-4.0.md
Outdated
|
||
* Deprecated the `add` method in favor of the `addWorkflow` method in `Workflow\Registry` | ||
* Deprecated the interface `SupportStrategyInterface` in favor of the interface `SupportStrategyWorkflowInterface` | ||
|
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.
And now there are two spaces here. You need to configure your editor to remove automatically all trailing spaces :D
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.
Yeah, you are right, I didn't configure it to do so !
{ | ||
if ($supportStrategy instanceof SupportStrategyInterface) { | ||
@trigger_error('Passing a "SupportStrategyInterface" in "Registry::addWorkflow" is deprecated since 4.0. Use "SupportStrategyWorkflowInterface" instead.', E_USER_DEPRECATED); | ||
} elseif (!($supportStrategy instanceof SupportStrategyWorkflowInterface || $supportStrategy instanceof SupportStrategyInterface)) { |
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 looks like you did not simplified the condition.
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.
Yeah, sorry, that's modified.
6902c37
to
116d678
Compare
public function addWorkflow(WorkflowInterface $workflow, $supportStrategy) | ||
{ | ||
if ($supportStrategy instanceof SupportStrategyInterface) { | ||
@trigger_error('Passing a "SupportStrategyInterface" in "Registry::addWorkflow" is deprecated since 4.0. Use "SupportStrategyWorkflowInterface" instead.', E_USER_DEPRECATED); |
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.
strings should be replaced SupportsStrategyInterface::class
, __METHOD
and SupportStrategyWorkflowInterface::class
in this order, we always use FQCNs
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 for the exception below
|
||
/** | ||
* @author Andreas Kleemann <[email protected]> | ||
*/ | ||
final class ClassInstanceSupportStrategy implements SupportStrategyInterface | ||
final class ClassInstanceSupportStrategy implements SupportStrategyWorkflowInterface |
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 implementing the old interface is a BC break ($strategy instanceof SupportsStrategyInterface
returning false). Personally I wouldn't care, this could be internal
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 is internal too.
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.
Internal should be hinted by an annotation, we can't have a policy of telling "that's internal" and break BC.
I suggest to open a PR against 3.4 to really mark them internal so that we're free to change in 4.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.
Ill open that PR.
116d678
to
6503755
Compare
} | ||
|
||
/** | ||
* @return string |
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.
aren't we trying to get rid of these kind docblocks?
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.
👍 useless
@@ -6,20 +6,26 @@ | |||
use Symfony\Component\Workflow\SupportStrategy\ClassInstanceSupportStrategy; | |||
use Symfony\Component\Workflow\Workflow; | |||
|
|||
/** | |||
* @group legacy |
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 file basically only needs this change.. what about SubjectA
+ SubjectB
for the new test?
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.
done
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.
still.. no real reason to optimize/tweak a legacy test (::class
notation, class removals). Doesnt hurt; just extra diff :)
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.
indeed, adding the ::class
notation was ok because the line was actually changed. Now it just gives merge conflicts, should be reverted
* @param Workflow $workflow | ||
* @param SupportStrategyInterface $supportStrategy | ||
* @param Workflow $workflow | ||
* @param WorkflowSupportStrategyInterface $supportStrategy |
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 BC layer actually expects a SupportStrategyInterface
? Using the new strategy interface should only go via addWorkflow
IMHO.
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.
Agree
cab29ee
to
860a174
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.
nice work :) i also asked @nicolas-grekas if this is really the desired upgrade path.
Basically i see one other option; to make Registry
final since 3.4, so we can keep favoring add()
; meaning less upgrade hassle for users as the common usecase would keep working, given Workflow implements WorkflowInterface
tomorrow.
Also means we close extensibility on Registry
, which we can open by introducing a RegistryInterface
, when needed.
@@ -25,13 +26,17 @@ class Registry | |||
/** | |||
* @param Workflow $workflow | |||
* @param SupportStrategyInterface $supportStrategy | |||
* | |||
* @deprecated since Symfony 4.1. Use addWorkflow() instead. |
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.
@deprecated since version 4.1, to be removed in 5.0. Use addWorkflow() instead.
*/ | ||
public function add(Workflow $workflow, $supportStrategy) | ||
{ | ||
if (!$supportStrategy instanceof SupportStrategyInterface) { |
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.
doesnt hurt to keep right? or why shouldnt it?
@@ -6,20 +6,26 @@ | |||
use Symfony\Component\Workflow\SupportStrategy\ClassInstanceSupportStrategy; | |||
use Symfony\Component\Workflow\Workflow; | |||
|
|||
/** | |||
* @group legacy |
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.
still.. no real reason to optimize/tweak a legacy test (::class
notation, class removals). Doesnt hurt; just extra diff :)
*/ | ||
public function getEnabledTransitions($subject); | ||
|
||
public function getName(); |
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 type info + {@inheritdoc} in sub class (id prefer a @return string
here).
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.
maybe we could typehint it instead of phpdoc ?
WDYT of @ro0NL's path ? It's not too late to say that Registry is final since 3.4 @nicolas-grekas ? I guess it could be a thing too to be able to re-implement the registry, and users won't need to change alot of thing. I think it's a good idea @ro0NL. (i'll take care of the comments, I just want to wait a little for others' thoughts). |
It is to me, 3.4 should not receive new deprecations anymore. I think this is fine. |
Ill take care of the 2 comments. |
👍 lets go with |
Needs a rebase. |
1f0be16
to
41d3793
Compare
The PR has been rebased |
*/ | ||
public function getEnabledTransitions($subject); | ||
|
||
public function getName(): string; |
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.
return type should be removed, otherwise it requires to add it to Workflow::getName()
which would break BC
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.
removed
41d3793
to
a533a00
Compare
Looks good to me. |
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.
Sorry, I left one (two) extra comment.
I'm 👍 after the changes.
* @param WorkflowInterface $workflow | ||
* @param object $subject | ||
* | ||
* @return bool |
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.
Sorry about asking again some change, but we don't need this PHP doc. Could you remove it?
Thanks
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.
Don't be sorry, that's why the PR are made for ;)
UPGRADE-4.1.md
Outdated
Workflow | ||
-------- | ||
|
||
* Deprecated the `add` method in favor of the `addWorkflow` method in `Workflow\Registry` |
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 I asked a mandatory change, Can I also ask you to add a final dot on each line of each .md updated?
a533a00
to
e8351d8
Compare
done @lyrixx |
This PR is ready. |
It took time, but here we go, this is in now. Thank you very much Hamza. |
This PR was merged into the 4.1-dev branch. Discussion ---------- [Workflow] Introduce a Workflow interface | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #23910 | License | MIT | Doc PR | todo @chalasr I think all the points you made in 23910 has been done. Needs to update the docs too. Commits ------- e8351d8 [Workflow] Introduce a Workflow interface
🎉 Thanks for your time @lyrixx @ro0NL @xabbuh @chalasr @nicolas-grekas |
…(derrabus) This PR was merged into the 6.4 branch. Discussion ---------- [TwigBridge] Remove obsolete Workflow feature detection | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | N/A The classes and methods that are detected here have been introduced with #24751 and #26092 (both Symfony 4.1) Commits ------- 7e9d5bb [TwigBridge] Remove obsolete Workflow feature detection
@chalasr I think all the points you made in 23910 has been done. Needs to update the docs too.