Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2df4a22

Browse files
committed
[Scheduler] have TriggerInterface extend \Stringable
1 parent f2ff84f commit 2df4a22

File tree

6 files changed

+28
-3
lines changed

6 files changed

+28
-3
lines changed

src/Symfony/Component/Scheduler/Tests/Generator/MessageGeneratorTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ public static function messagesProvider(): \Generator
135135
],
136136
'schedule' => [
137137
RecurringMessage::trigger(new class() implements TriggerInterface {
138+
public function __toString(): string
139+
{
140+
return 'foo';
141+
}
142+
138143
public function getNextRunDate(\DateTimeImmutable $run): ?\DateTimeImmutable
139144
{
140145
return null;

src/Symfony/Component/Scheduler/Trigger/CallbackTrigger.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@ final class CallbackTrigger implements TriggerInterface
2020
{
2121
private \Closure $callback;
2222

23-
public function __construct(callable $callback)
23+
public function __construct(callable $callback, private string $description)
2424
{
2525
$this->callback = $callback(...);
2626
}
2727

28+
public function __toString(): string
29+
{
30+
return $this->description;
31+
}
32+
2833
public function getNextRunDate(\DateTimeImmutable $run): ?\DateTimeImmutable
2934
{
3035
return ($this->callback)($run);

src/Symfony/Component/Scheduler/Trigger/CronExpressionTrigger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* @experimental
2323
*/
24-
final class CronExpressionTrigger implements TriggerInterface, \Stringable
24+
final class CronExpressionTrigger implements TriggerInterface
2525
{
2626
public function __construct(
2727
private readonly CronExpression $expression = new CronExpression('* * * * *'),

src/Symfony/Component/Scheduler/Trigger/DatePeriodTrigger.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ public function __construct(
2121
) {
2222
}
2323

24+
public function __toString(): string
25+
{
26+
return sprintf(
27+
'%s - %s, %s',
28+
$this->period->getStartDate()->format(\DateTimeInterface::ATOM),
29+
$this->period->getEndDate()?->format(\DateTimeInterface::ATOM) ?? '(inf)',
30+
'every ?',
31+
);
32+
}
33+
2434
public function getNextRunDate(\DateTimeImmutable $run): ?\DateTimeImmutable
2535
{
2636
$iterator = $this->period->getIterator();

src/Symfony/Component/Scheduler/Trigger/ExcludeTimeTrigger.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public function __construct(
2323
) {
2424
}
2525

26+
public function __toString(): string
27+
{
28+
return sprintf('%s, from: %s, until: %s', $this->inner, $this->from->format(\DateTimeInterface::ATOM), $this->until->format(\DateTimeInterface::ATOM));
29+
}
30+
2631
public function getNextRunDate(\DateTimeImmutable $run): ?\DateTimeImmutable
2732
{
2833
$nextRun = $this->inner->getNextRunDate($run);

src/Symfony/Component/Scheduler/Trigger/TriggerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* @experimental
1616
*/
17-
interface TriggerInterface
17+
interface TriggerInterface extends \Stringable
1818
{
1919
public function getNextRunDate(\DateTimeImmutable $run): ?\DateTimeImmutable;
2020
}

0 commit comments

Comments
 (0)