[Workflow] Trigger entered
event for subject entering in the Workflow for the first time
This commit is contained in:
parent
8d277ce3e5
commit
388840fd99
@ -1,6 +1,11 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
4.3.0
|
||||
-----
|
||||
|
||||
* Trigger `entered` event for subject entering in the Workflow for the first time
|
||||
|
||||
4.1.0
|
||||
-----
|
||||
|
||||
|
@ -35,7 +35,7 @@ class Event extends BaseEvent
|
||||
* @param Transition $transition
|
||||
* @param WorkflowInterface $workflow
|
||||
*/
|
||||
public function __construct($subject, Marking $marking, Transition $transition, $workflow = null)
|
||||
public function __construct($subject, Marking $marking, Transition $transition = null, $workflow = null)
|
||||
{
|
||||
$this->subject = $subject;
|
||||
$this->marking = $marking;
|
||||
|
@ -373,6 +373,8 @@ class WorkflowTest extends TestCase
|
||||
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $eventDispatcher, 'workflow_name');
|
||||
|
||||
$eventNameExpected = array(
|
||||
'workflow.entered',
|
||||
'workflow.workflow_name.entered',
|
||||
'workflow.guard',
|
||||
'workflow.workflow_name.guard',
|
||||
'workflow.workflow_name.guard.t1',
|
||||
|
@ -61,6 +61,8 @@ class Workflow implements WorkflowInterface
|
||||
|
||||
// update the subject with the new marking
|
||||
$this->markingStore->setMarking($subject, $marking);
|
||||
|
||||
$this->entered($subject, null, $marking);
|
||||
}
|
||||
|
||||
// check that the subject has a known place
|
||||
@ -323,7 +325,7 @@ class Workflow implements WorkflowInterface
|
||||
}
|
||||
}
|
||||
|
||||
private function entered($subject, Transition $transition, Marking $marking): void
|
||||
private function entered($subject, Transition $transition = null, Marking $marking): void
|
||||
{
|
||||
if (null === $this->dispatcher) {
|
||||
return;
|
||||
@ -334,10 +336,12 @@ class Workflow implements WorkflowInterface
|
||||
$this->dispatcher->dispatch('workflow.entered', $event);
|
||||
$this->dispatcher->dispatch(sprintf('workflow.%s.entered', $this->name), $event);
|
||||
|
||||
if ($transition) {
|
||||
foreach ($transition->getTos() as $place) {
|
||||
$this->dispatcher->dispatch(sprintf('workflow.%s.entered.%s', $this->name, $place), $event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function completed($subject, Transition $transition, Marking $marking): void
|
||||
{
|
||||
|
Reference in New Issue
Block a user