diff --git a/src/Symfony/Component/Scheduler/Schedule.php b/src/Symfony/Component/Scheduler/Schedule.php index 4ccd88ff7a6e9..bd413892bc671 100644 --- a/src/Symfony/Component/Scheduler/Schedule.php +++ b/src/Symfony/Component/Scheduler/Schedule.php @@ -141,6 +141,10 @@ public function getSchedule(): static public function before(callable $listener, int $priority = 0): static { + if (!$this->dispatcher) { + throw new LogicException(sprintf('To register a listener with "%s()", you need to set an event dispatcher on the Schedule.', __METHOD__)); + } + $this->dispatcher->addListener(PreRunEvent::class, $listener, $priority); return $this; @@ -148,6 +152,10 @@ public function before(callable $listener, int $priority = 0): static public function after(callable $listener, int $priority = 0): static { + if (!$this->dispatcher) { + throw new LogicException(sprintf('To register a listener with "%s()", you need to set an event dispatcher on the Schedule.', __METHOD__)); + } + $this->dispatcher->addListener(PostRunEvent::class, $listener, $priority); return $this; @@ -155,6 +163,10 @@ public function after(callable $listener, int $priority = 0): static public function onFailure(callable $listener, int $priority = 0): static { + if (!$this->dispatcher) { + throw new LogicException(sprintf('To register a listener with "%s()", you need to set an event dispatcher on the Schedule.', __METHOD__)); + } + $this->dispatcher->addListener(FailureEvent::class, $listener, $priority); return $this;
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: