-
-
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
Merged
lyrixx
merged 1 commit into
symfony:master
from
Simperfit:feature/introduce-an-interface-for-the-workflow-component
Dec 7, 2017
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
|
||
use Symfony\Component\Workflow\Exception\InvalidArgumentException; | ||
use Symfony\Component\Workflow\SupportStrategy\SupportStrategyInterface; | ||
use Symfony\Component\Workflow\SupportStrategy\WorkflowSupportStrategyInterface; | ||
|
||
/** | ||
* @author Fabien Potencier <[email protected]> | ||
|
@@ -25,13 +26,17 @@ class Registry | |
/** | ||
* @param Workflow $workflow | ||
* @param SupportStrategyInterface $supportStrategy | ||
* | ||
* @deprecated since version 4.1, to be removed in 5.0. Use addWorkflow() instead. | ||
*/ | ||
public function add(Workflow $workflow, $supportStrategy) | ||
{ | ||
if (!$supportStrategy instanceof SupportStrategyInterface) { | ||
throw new \InvalidArgumentException('The "supportStrategy" is not an instance of SupportStrategyInterface.'); | ||
} | ||
@trigger_error(sprintf('%s is deprecated since Symfony 4.1. Use addWorkflow() instead.', __METHOD__), E_USER_DEPRECATED); | ||
$this->workflows[] = array($workflow, $supportStrategy); | ||
} | ||
|
||
public function addWorkflow(WorkflowInterface $workflow, WorkflowSupportStrategyInterface $supportStrategy) | ||
{ | ||
$this->workflows[] = array($workflow, $supportStrategy); | ||
} | ||
|
||
|
@@ -61,7 +66,7 @@ public function get($subject, $workflowName = null) | |
return $matched; | ||
} | ||
|
||
private function supports(Workflow $workflow, SupportStrategyInterface $supportStrategy, $subject, $workflowName): bool | ||
private function supports(WorkflowInterface $workflow, $supportStrategy, $subject, $workflowName): bool | ||
{ | ||
if (null !== $workflowName && $workflowName !== $workflow->getName()) { | ||
return false; | ||
|
13 changes: 13 additions & 0 deletions
13
src/Symfony/Component/Workflow/SupportStrategy/ClassInstanceSupportStrategy.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Workflow\SupportStrategy; | ||
|
||
@trigger_error(sprintf('"%s" is deprecated since Symfony 4.1. Use "%s" instead.', ClassInstanceSupportStrategy::class, InstanceOfSupportStrategy::class), E_USER_DEPRECATED); | ||
|
||
use Symfony\Component\Workflow\Workflow; | ||
|
||
/** | ||
* @author Andreas Kleemann <[email protected]> | ||
* | ||
* @deprecated since version 4.1, to be removed in 5.0. Use InstanceOfSupportStrategy instead | ||
*/ | ||
final class ClassInstanceSupportStrategy implements SupportStrategyInterface | ||
{ | ||
|
41 changes: 41 additions & 0 deletions
41
src/Symfony/Component/Workflow/SupportStrategy/InstanceOfSupportStrategy.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Workflow\SupportStrategy; | ||
|
||
use Symfony\Component\Workflow\WorkflowInterface; | ||
|
||
/** | ||
* @author Andreas Kleemann <[email protected]> | ||
* @author Amrouche Hamza <[email protected]> | ||
*/ | ||
final class InstanceOfSupportStrategy implements WorkflowSupportStrategyInterface | ||
{ | ||
private $className; | ||
|
||
public function __construct(string $className) | ||
{ | ||
$this->className = $className; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supports(WorkflowInterface $workflow, $subject): bool | ||
{ | ||
return $subject instanceof $this->className; | ||
} | ||
|
||
public function getClassName(): string | ||
{ | ||
return $this->className; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
|
||
/** | ||
* @author Andreas Kleemann <[email protected]> | ||
* | ||
* @deprecated since version 4.1, to be removed in 5.0. Use WorkflowSupportStrategyInterface instead | ||
*/ | ||
interface SupportStrategyInterface | ||
{ | ||
|
22 changes: 22 additions & 0 deletions
22
src/Symfony/Component/Workflow/SupportStrategy/WorkflowSupportStrategyInterface.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Workflow\SupportStrategy; | ||
|
||
use Symfony\Component\Workflow\WorkflowInterface; | ||
|
||
/** | ||
* @author Amrouche Hamza <[email protected]> | ||
*/ | ||
interface WorkflowSupportStrategyInterface | ||
{ | ||
public function supports(WorkflowInterface $workflow, $subject): bool; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/Symfony/Component/Workflow/Tests/SupportStrategy/InstanceOfSupportStrategyTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Symfony\Component\Workflow\Tests\SupportStrategy; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Workflow\SupportStrategy\InstanceOfSupportStrategy; | ||
use Symfony\Component\Workflow\Workflow; | ||
|
||
class InstanceOfSupportStrategyTest extends TestCase | ||
{ | ||
public function testSupportsIfClassInstance() | ||
{ | ||
$strategy = new InstanceOfSupportStrategy(Subject1::class); | ||
|
||
$this->assertTrue($strategy->supports($this->createWorkflow(), new Subject1())); | ||
} | ||
|
||
public function testSupportsIfNotClassInstance() | ||
{ | ||
$strategy = new InstanceOfSupportStrategy(Subject2::class); | ||
|
||
$this->assertFalse($strategy->supports($this->createWorkflow(), new Subject1())); | ||
} | ||
|
||
private function createWorkflow() | ||
{ | ||
return $this->getMockBuilder(Workflow::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
} | ||
} | ||
|
||
class Subject1 | ||
{ | ||
} | ||
class Subject2 | ||
{ | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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