Skip to content

[Workflow] Added the workflow name to all events dispatched #21925

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

Merged
merged 1 commit into from
Mar 8, 2017
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 @@ -7,3 +7,4 @@ CHANGELOG
* Added `workflow.entered` events which is fired after the marking has been set.
* Deprecated class name support in `WorkflowRegistry::add()` as second parameter.
Wrap the class name in an instance of ClassInstanceSupportStrategy instead.
* Added support for `Event::getWorkflowName()`.
10 changes: 9 additions & 1 deletion src/Symfony/Component/Workflow/Event/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@ class Event extends BaseEvent
private $subject;
private $marking;
private $transition;
private $workflowName;

/**
* @param object $subject
* @param Marking $marking
* @param Transition $transition
* @param string $workflowName
*/
public function __construct($subject, Marking $marking, Transition $transition)
public function __construct($subject, Marking $marking, Transition $transition, $workflowName = 'unnamed')
{
$this->subject = $subject;
$this->marking = $marking;
$this->transition = $transition;
$this->workflowName = $workflowName;
}

public function getMarking()
Expand All @@ -51,4 +54,9 @@ public function getTransition()
{
return $this->transition;
}

public function getWorkflowName()
{
return $this->workflowName;
}
}
10 changes: 5 additions & 5 deletions src/Symfony/Component/Workflow/Workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private function guardTransition($subject, Marking $marking, Transition $transit
return;
}

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

$this->dispatcher->dispatch('workflow.guard', $event);
$this->dispatcher->dispatch(sprintf('workflow.%s.guard', $this->name), $event);
Expand All @@ -226,7 +226,7 @@ private function guardTransition($subject, Marking $marking, Transition $transit
private function leave($subject, Transition $transition, Marking $marking)
{
if (null !== $this->dispatcher) {
$event = new Event($subject, $marking, $transition);
$event = new Event($subject, $marking, $transition, $this->name);

$this->dispatcher->dispatch('workflow.leave', $event);
$this->dispatcher->dispatch(sprintf('workflow.%s.leave', $this->name), $event);
Expand All @@ -247,7 +247,7 @@ private function transition($subject, Transition $transition, Marking $marking)
return;
}

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

$this->dispatcher->dispatch('workflow.transition', $event);
$this->dispatcher->dispatch(sprintf('workflow.%s.transition', $this->name), $event);
Expand All @@ -257,7 +257,7 @@ private function transition($subject, Transition $transition, Marking $marking)
private function enter($subject, Transition $transition, Marking $marking)
{
if (null !== $this->dispatcher) {
$event = new Event($subject, $marking, $transition);
$event = new Event($subject, $marking, $transition, $this->name);

$this->dispatcher->dispatch('workflow.enter', $event);
$this->dispatcher->dispatch(sprintf('workflow.%s.enter', $this->name), $event);
Expand All @@ -278,7 +278,7 @@ private function entered($subject, Transition $transition, Marking $marking)
return;
}

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

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