Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Component/Workflow/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
-----

* Added support for `Event::getWorkflowName()` for "announce" events.
* Added `workflow.completed` events which are fired after a transition is completed.

3.3.0
-----
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Workflow/Tests/WorkflowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ public function testApplyWithEventDispatcher()
'workflow.workflow_name.entered',
'workflow.workflow_name.entered.b',
'workflow.workflow_name.entered.c',
'workflow.completed',
'workflow.workflow_name.completed',
'workflow.workflow_name.completed.t1',
// Following events are fired because of announce() method
'workflow.announce',
'workflow.workflow_name.announce',
Expand Down
15 changes: 15 additions & 0 deletions src/Symfony/Component/Workflow/Workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ public function apply($subject, $transitionName)

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

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

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

Expand Down Expand Up @@ -309,6 +311,19 @@ private function entered($subject, Transition $transition, Marking $marking)
}
}

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

$event = new Event($subject, $marking, $transition, $this->name);

$this->dispatcher->dispatch('workflow.completed', $event);
$this->dispatcher->dispatch(sprintf('workflow.%s.completed', $this->name), $event);
$this->dispatcher->dispatch(sprintf('workflow.%s.completed.%s', $this->name, $transition->getName()), $event);
}

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