Skip to content
Merged
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
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