8000 [Workflow] #24501 Transition blockers. · d-ph/symfony@492080b · GitHub
[go: up one dir, main page]

Skip to conten 8000 t

Commit 492080b

Browse files
author
d-ph
committed
[Workflow] symfony#24501 Transition blockers.
1 parent 5960cdb commit 492080b

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/Symfony/Component/Workflow/Event/GuardEvent.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
*/
2323
class GuardEvent extends Event
2424
{
25-
private $blocked = false;
2625
private $transitionBlockerList;
2726

2827
/**
@@ -37,12 +36,17 @@ public function __construct($subject, Marking $marking, Transition $transition,
3736

3837
public function isBlocked()
3938
{
40-
return $this->blocked;
39+
return 0 !== count($this->transitionBlockerList);
4140
}
4241

4342
public function setBlocked($blocked)
4443
{
45-
$this->blocked = (bool) $blocked;
44+
if (!$blocked) {
45+
$this->transitionBlockerList = new TransitionBlockerList();
46+
return;
47+
}
48+
49+
$this->transitionBlockerList->add(TransitionBlocker::createUnknownReason($this->getTransition()->getName()));
4650
}
4751

4852
/**
@@ -58,7 +62,5 @@ public function getTransitionBlockerList()
5862
public function addTransitionBlocker(TransitionBlocker $transitionBlocker)
5963
{
6064
$this->transitionBlockerList->add($transitionBlocker);
61-
62-
$this->setBlocked(true);
6365
}
6466
}

src/Symfony/Component/Workflow/TransitionBlocker.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class TransitionBlocker
1818
{
1919
const REASON_CODE_TRANSITION_NOT_DEFINED = 'com.symfony.www.workflow.transition_blocker.not_defined';
2020
const REASON_CODE_TRANSITION_NOT_APPLICABLE = 'com.symfony.www.workflow.transition_blocker.not_applicable';
21+
const REASON_CODE_UNKNOWN = 'com.symfony.www.workflow.transition_blocker.unknown';
2122

2223
private $message;
2324
private $code;
@@ -71,6 +72,24 @@ public static function createNotApplicable(string $transitionName)
7172
);
7273
}
7374

75+
/**
76+
* Create a blocker, that says the transition cannot be made because of unknown
77+
* reason.
78+
*
79+
* This blocker code is chiefly for preserving backwards compatibility.
80+
*
81+
* @param string $transitionName
82+
*
83+
* @return static
84+
*/
85+
public static function createUnknownReason(string $transitionName)
86+
{
87+
return new static(
88+
sprintf('Transition "%s" cannot be made, because of unknown reason.', $transitionName),
89+
self::REASON_CODE_UNKNOWN
90+
);
91+
}
92+
7493
/**
7594
* Converts the blocker into a string for debugging purposes.
7695
*

0 commit comments

Comments
 (0)
0