Skip to content

[Workflow] Adding workflow name to the announce event #23593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 5 additions & 0 deletions src/Symfony/Component/Workflow/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

3.4.0
-----

* Added support for `Event::getWorkflowName()` for "announce" events.

3.3.0
-----

Expand Down
29 changes: 29 additions & 0 deletions src/Symfony/Component/Workflow/Tests/WorkflowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,35 @@ public function testApplyWithEventDispatcher()
$this->assertSame($eventNameExpected, $eventDispatcher->dispatchedEvents);
}

public function testEventName()
{
$definition = $this->createComplexWorkflowDefinition();
$subject = new \stdClass();
$subject->marking = null;
$dispatcher = new EventDispatcher();
$name = 'workflow_name';
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $dispatcher, $name);

$assertWorkflowName = function (Event $event) use ($name) {
$this->assertEquals($name, $event->getWorkflowName());
};

$eventNames = array(
'workflow.guard',
'workflow.leave',
'workflow.transition',
'workflow.enter',
'workflow.entered',
'workflow.announce',
);

foreach ($eventNames as $eventName) {
$dispatcher->addListener($eventName, $assertWorkflowName);
}

$workflow->apply($subject, 't1');
}

public function testMarkingStateOnApplyWithEventDispatcher()
{
$definition = new Definition(range('a', 'f'), array(new Transition('t', range('a', 'c'), range('d', 'f'))));
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Workflow/Workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ private function announce($subject, Transition $initialTransition, Marking $mark
return;
}

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

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