Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9b50a92

Browse files
committed
bug #57282 [Scheduler] Throw an exception when no dispatcher has been passed to a Schedule (fabpot)
This PR was merged into the 6.4 branch. Discussion ---------- [Scheduler] Throw an exception when no dispatcher has been passed to a Schedule | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Issues | Fix #53722 <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT Commits ------- dfd65d6 [Scheduler] Throw an exception when no dispatcher has been passed to a Schedule
2 parents d9367f9 + dfd65d6 commit 9b50a92

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/Symfony/Component/Scheduler/Schedule.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,32 @@ public function getSchedule(): static
141141

142142
public function before(callable $listener, int $priority = 0): static
143143
{
144+
if (!$this->dispatcher) {
145+
throw new LogicException(sprintf('To register a listener with "%s()", you need to set an event dispatcher on the Schedule.', __METHOD__));
146+
}
147+
144148
$this->dispatcher->addListener(PreRunEvent::class, $listener, $priority);
145149

146150
return $this;
147151
}
148152

149153
public function after(callable $listener, int $priority = 0): static
150154
{
155+
if (!$this->dispatcher) {
156+
throw new LogicException(sprintf('To register a listener with "%s()", you need to set an event dispatcher on the Schedule.', __METHOD__));
157+
}
158+
151159
$this->dispatcher->addListener(PostRunEvent::class, $listener, $priority);
152160

153161
return $this;
154162
}
155163

156164
public function onFailure(callable $listener, int $priority = 0): static
157165
{
166+
if (!$this->dispatcher) {
167+
throw new LogicException(sprintf('To register a listener with "%s()", you need to set an event dispatcher on the Schedule.', __METHOD__));
168+
}
169+
158170
$this->dispatcher->addListener(FailureEvent::class, $listener, $priority);
159171

160172
return $this;

0 commit comments

Comments
 (0)