Skip to content

Commit

Permalink
feature #20787 [Workflow] Added an entered event (Padam87)
Browse files Browse the repository at this point in the history
This PR was submitted for the 3.2 branch but it was merged into the 3.3-dev branch instead (closes #20787).

Discussion
----------

[Workflow] Added an entered event

| Q             | A
| ------------- | ---
| Branch?       |  3.2
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #20774 (partially) ; #21433
| License       | MIT
| Doc PR        | -

Commits
-------

7a562bd [Workflow] Added an entered event
  • Loading branch information
lyrixx committed Feb 13, 2017
2 parents 91904af + 7a562bd commit 772d8e6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Symfony/Component/Workflow/Tests/WorkflowTest.php
Expand Up @@ -239,6 +239,10 @@ public function testApplyWithEventDispatcher()
'workflow.workflow_name.enter',
'workflow.workflow_name.enter.b',
'workflow.workflow_name.enter.c',
'workflow.entered',
'workflow.workflow_name.entered',
'workflow.workflow_name.entered.b',
'workflow.workflow_name.entered.c',
// Following events are fired because of announce() method
'workflow.guard',
'workflow.workflow_name.guard',
Expand Down
18 changes: 18 additions & 0 deletions src/Symfony/Component/Workflow/Workflow.php
Expand Up @@ -140,6 +140,8 @@ public function apply($subject, $transitionName)

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

$this->entered($subject, $transition, $marking);

$this->announce($subject, $transition, $marking);
}

Expand Down Expand Up @@ -270,6 +272,22 @@ private function enter($subject, Transition $transition, Marking $marking)
}
}

private function entered($subject, Transition $transition, Marking $marking)
{
if (null === $this->dispatcher) {
return;
}

$event = new Event($subject, $marking, $transition);

$this->dispatcher->dispatch('workflow.entered', $event);
$this->dispatcher->dispatch(sprintf('workflow.%s.entered', $this->name), $event);

foreach ($transition->getTos() as $place) {
$this->dispatcher->dispatch(sprintf('workflow.%s.entered.%s', $this->name, $place), $event);
}
}

private function announce($subject, Transition $initialTransition, Marking $marking)
{
if (null === $this->dispatcher) {
Expand Down

0 comments on commit 772d8e6

Please sign in to comment.