Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #26076 [Workflow] Add transition blockers (d-ph, lyrixx)
This PR was merged into the 4.1-dev branch. Discussion ---------- [Workflow] Add transition blockers | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #24745 #24501 | License | MIT Commits ------- 2b8faff [Workflow] Cleaned the transition blocker implementations 4d10e10 [Workflow] Add transition blockers
- Loading branch information
Showing
10 changed files
with
438 additions
and
65 deletions.
There are no files selected for viewing
This file contains 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 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 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
36 changes: 36 additions & 0 deletions
36
src/Symfony/Component/Workflow/Exception/NotEnabledTransitionException.php
This file contains 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,36 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Workflow\Exception; | ||
|
||
use Symfony\Component\Workflow\TransitionBlockerList; | ||
|
||
/** | ||
* Thrown by Workflow when a not enabled transition is applied on a subject. | ||
* | ||
* @author Grégoire Pineau <lyrixx@lyrixx.info> | ||
*/ | ||
class NotEnabledTransitionException extends LogicException | ||
{ | ||
private $transitionBlockerList; | ||
|
||
public function __construct(string $transitionName, string $workflowName, TransitionBlockerList $transitionBlockerList) | ||
{ | ||
parent::__construct(sprintf('Transition "%s" is not enabled for workflow "%s".', $transitionName, $workflowName)); | ||
|
||
$this->transitionBlockerList = $transitionBlockerList; | ||
} | ||
|
||
public function getTransitionBlockerList(): TransitionBlockerList | ||
{ | ||
return $this->transitionBlockerList; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Symfony/Component/Workflow/Exception/UndefinedTransitionException.php
This file contains 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,25 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Workflow\Exception; | ||
|
||
/** | ||
* Thrown by Workflow when an undefined transition is applied on a subject. | ||
* | ||
* @author Grégoire Pineau <lyrixx@lyrixx.info> | ||
*/ | ||
class UndefinedTransitionException extends LogicException | ||
{ | ||
public function __construct(string $transitionName, string $workflowName) | ||
{ | ||
parent::__construct(sprintf('Transition "%s" is not defined for workflow "%s".', $transitionName, $workflowName)); | ||
} | ||
} |
This file contains 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 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,91 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Workflow; | ||
|
||
/** | ||
* A reason why a transition cannot be performed for a subject. | ||
*/ | ||
final class TransitionBlocker | ||
{ | ||
const BLOCKED_BY_MARKING = '19beefc8-6b1e-4716-9d07-a39bd6d16e34'; | ||
const BLOCKED_BY_EXPRESSION_GUARD_LISTENER = '326a1e9c-0c12-11e8-ba89-0ed5f89f718b'; | ||
const UNKNOWN = 'e8b5bbb9-5913-4b98-bfa6-65dbd228a82a'; | ||
|
||
private $message; | ||
private $code; | ||
private $parameters; | ||
|
||
/** | ||
* @param string $code Code is a machine-readable string, usually an UUID | ||
* @param array $parameters This is useful if you would like to pass around the condition values, that | ||
* blocked the transition. E.g. for a condition "distance must be larger than | ||
* 5 miles", you might want to pass around the value of 5. | ||
*/ | ||
public function __construct(string $message, string $code, array $parameters = array()) | ||
{ | ||
$this->message = $message; | ||
$this->code = $code; | ||
$this->parameters = $parameters; | ||
} | ||
|
||
/** | ||
* Create a blocker that says the transition cannot be made because it is | ||
* not enabled. | ||
* | ||
* It means the subject is in wrong place (i.e. status): | ||
* * If the workflow is a state machine: the subject is not in the previous place of the transition. | ||
* * If the workflow is a workflow: the subject is not in all previous places of the transition. | ||
*/ | ||
public static function createBlockedByMarking(Marking $marking): self | ||
{ | ||
return new static('The marking does not enable the transition.', self::BLOCKED_BY_MARKING, array( | ||
'marking' => $marking, | ||
)); | ||
} | ||
|
||
/** | ||
* Creates a blocker that says the transition cannot be made because it has | ||
* been blocked by the expression guard listener. | ||
*/ | ||
public static function createBlockedByExpressionGuardListener(string $expression): self | ||
{ | ||
return new static('The expression blocks the transition.', self::BLOCKED_BY_EXPRESSION_GUARD_LISTENER, array( | ||
'expression' => $expression, | ||
)); | ||
} | ||
|
||
/** | ||
* Creates a blocker that says the transition cannot be made because of an | ||
* unknown reason. | ||
* | ||
* This blocker code is chiefly for preserving backwards compatibility. | ||
*/ | ||
public static function createUnknown(): self | ||
{ | ||
return new static('Unknown reason.', self::UNKNOWN); | ||
} | ||
|
||
public function getMessage(): string | ||
{ | ||
return $this->message; | ||
} | ||
|
||
public function getCode(): string | ||
{ | ||
return $this->code; | ||
} | ||
|
||
public function getParameters(): array | ||
{ | ||
return $this->parameters; | ||
} | ||
} |
Oops, something went wrong.