Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7c7725c

Browse files
committed
[Workflow] Added an entered event
1 parent 81ad336 commit 7c7725c

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ public function testApplyWithEventDispatcher()
239239
'workflow.workflow_name.enter',
240240
'workflow.workflow_name.enter.b',
241241
'workflow.workflow_name.enter.c',
242+
'workflow.entered',
243+
'workflow.workflow_name.entered',
244+
'workflow.workflow_name.entered.b',
245+
'workflow.workflow_name.entered.c',
242246
// Following events are fired because of announce() method
243247
'workflow.guard',
244248
'workflow.workflow_name.guard',

src/Symfony/Component/Workflow/Workflow.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ public function apply($subject, $transitionName)
140140

141141
$this->markingStore->setMarking($subject, $marking);
142142

143+
$this->entered($subject, $transition, $marking);
144+
143145
$this->announce($subject, $transition, $marking);
144146
}
145147

@@ -270,6 +272,22 @@ private function enter($subject, Transition $transition, Marking $marking)
270272
}
271273
}
272274

275+
private function entered($subject, Transition $transition, Marking $marking)
276+
{
277+
if (null === $this->dispatcher) {
278+
return;
279+
}
280+
281+
$event = new Event($subject, $marking, $transition);
282+
283+
$this->dispatcher->dispatch('workflow.entered', $event);
284+
$this->dispatcher->dispatch(sprintf('workflow.%s.entered', $this->name), $event);
285+
286+
foreach ($transition->getTos() as $place) {
287+
$this->dispatcher->dispatch(sprintf('workflow.%s.entered.%s', $this->name, $place), $event);
288+
}
289+
}
290+
273291
private function announce($subject, Transition $initialTransition, Marking $marking)
274292
{
275293
if (null === $this->dispatcher) {

0 commit comments

Comments
 (0)