Skip to content

Commit dfd65d6

Browse files
committed
[Scheduler] Throw an exception when no dispatcher has been passed to a Schedule
1 parent d9367f9 commit dfd65d6

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy