Skip to content

Commit

Permalink
[Scheduler] Throw an exception when no dispatcher has been passed to …
Browse files Browse the repository at this point in the history
…a Schedule
  • Loading branch information
fabpot committed Jun 1, 2024
1 parent d9367f9 commit dfd65d6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Symfony/Component/Scheduler/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,32 @@ 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;
}

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;
}

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;
Expand Down

0 comments on commit dfd65d6

Please sign in to comment.