8000 [Workflow] Trigger `entered` event for subject entering in the Workfl… · symfony/symfony@388840f · GitHub
[go: up one dir, main page]

Skip to content

Commit 388840f

Browse files
committed
[Workflow] Trigger entered event for subject entering in the Workflow for the first time
1 parent 8d277ce commit 388840f

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

src/Symfony/Component/Workflow/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
4.3.0
5+
-----
6+
7+
* Trigger `entered` event for subject entering in the Workflow for the first time
8+
49
4.1.0
510
-----
611

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Event extends BaseEvent
3535
* @param Transition $transition
3636
* @param WorkflowInterface $workflow
3737
*/
38-
public function __construct($subject, Marking $marking, Transition $transition, $workflow = null)
38+
public function __construct($subject, Marking $marking, Transition $transition = null, $workflow = null)
3939
{
4040
$this->subject = $subject;
4141
$this->marking = $marking;

src/Symfony/Component/Workflow/Tests/WorkflowTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ public function testApplyWithEventDispatcher()
373373
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $eventDispatcher, 'workflow_name');
374374

375375
$eventNameExpected = array(
376+
'workflow.entered',
377+
'workflow.workflow_name.entered',
376378
'workflow.guard',
377379
'workflow.workflow_name.guard',
378380
'workflow.workflow_name.guard.t1',

src/Symfony/Component/Workflow/Workflow.php

Lines changed: 7 additions & 3 deletions
8000
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public function getMarking($subject)
6161

6262
// update the subject with the new marking
6363
$this->markingStore->setMarking($subject, $marking);
64+
65+
$this->entered($subject, null, $marking);
6466
}
6567

6668
// check that the subject has a known place
@@ -323,7 +325,7 @@ private function enter($subject, Transition $transition, Marking $marking): void
323325
}
324326
}
325327

326-
private function entered($subject, Transition $transition, Marking $marking): void
328+
private function entered($subject, Transition $transition = null, Marking $marking): void
327329
{
328330
if (null === $this->dispatcher) {
329331
return;
@@ -334,8 +336,10 @@ private function entered($subject, Transition $transition, Marking $marking): vo
334336
$this->dispatcher->dispatch('workflow.entered', $event);
335337
$this->dispatcher->dispatch(sprintf('workflow.%s.entered', $this->name), $event);
336338

337-
foreach ($transition->getTos() as $place) {
338-
$this->dispatcher->dispatch(sprintf('workflow.%s.entered.%s', $this->name, $place), $event);
339+
if ($transition) {
340+
foreach ($transition->getTos() as $place) {
341+
$this->dispatcher->dispatch(sprintf('workflow.%s.entered.%s', $this->name, $place), $event);
342+
}
339343
}
340344
}
341345

0 commit comments

Comments
 (0)
0