[Workflow] Added an entered event

This commit is contained in:
Adam Prager 2016-12-06 16:23:39 +01:00 committed by Grégoire Pineau
parent 91904af902
commit 7a562bd81e
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) {