Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Scheduler] have TriggerInterface extend \Stringable #49863

Merged
merged 1 commit into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ public static function messagesProvider(): \Generator
],
'schedule' => [
RecurringMessage::trigger(new class() implements TriggerInterface {
public function __toString(): string
{
return 'foo';
}

public function getNextRunDate(\DateTimeImmutable $run): ?\DateTimeImmutable
{
return null;
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Scheduler/Trigger/CallbackTrigger.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public function __construct(callable $callback)
$this->callback = $callback(...);
}

public function __toString(): string
{
return spl_object_hash($this->callback);
}

public function getNextRunDate(\DateTimeImmutable $run): ?\DateTimeImmutable
{
return ($this->callback)($run);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* @experimental
*/
final class CronExpressionTrigger implements TriggerInterface, \Stringable
final class CronExpressionTrigger implements TriggerInterface
{
public function __construct(
private readonly CronExpression $expression = new CronExpression('* * * * *'),
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/Scheduler/Trigger/DatePeriodTrigger.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ public function __construct(
) {
}

public function __toString(): string
{
return sprintf(
'%s - %s, %s',
$this->period->getStartDate()->format(\DateTimeInterface::ATOM),
$this->period->getEndDate()?->format(\DateTimeInterface::ATOM) ?? '(inf)',
'-',
);
}

public function getNextRunDate(\DateTimeImmutable $run): ?\DateTimeImmutable
{
$iterator = $this->period->getIterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public function __construct(
) {
}

public function __toString(): string
{
return sprintf('%s, from: %s, until: %s', $this->inner, $this->from->format(\DateTimeInterface::ATOM), $this->until->format(\DateTimeInterface::ATOM));
}

public function getNextRunDate(\DateTimeImmutable $run): ?\DateTimeImmutable
{
$nextRun = $this->inner->getNextRunDate($run);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* @experimental
*/
interface TriggerInterface
interface TriggerInterface extends \Stringable
{
public function getNextRunDate(\DateTimeImmutable $run): ?\DateTimeImmutable;
}