feature #20787 [Workflow] Added an entered event (Padam87)

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
-------

7a562bd81e [Workflow] Added an entered event
This commit is contained in:
Grégoire Pineau 2017-02-13 11:05:08 +01:00
commit 772d8e6066
2 changed files with 22 additions and 0 deletions

View File

@ -239,6 +239,10 @@ class WorkflowTest extends \PHPUnit_Framework_TestCase
'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',

View File

@ -140,6 +140,8 @@ class Workflow
$this->markingStore->setMarking($subject, $marking);
$this->entered($subject, $transition, $marking);
$this->announce($subject, $transition, $marking);
}
@ -270,6 +272,22 @@ class Workflow
}
}
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) {