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

Skip to content

Commit 8869bd7

Browse files
committed
apply feedback
1 parent d221fc0 commit 8869bd7

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

src/Symfony/Component/Scheduler/RecurringMessage.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ private function __construct(
4040
* * A relative date format as supported by \DateInterval;
4141
* * A \DateInterval instance.
4242
*
43+
* @param MessageProviderInterface|object $message A message provider that yields messages or a static message that will be dispatched on every trigger
44+
*
4345
* @see https://en.wikipedia.org/wiki/ISO_8601#Durations
4446
* @see https://php.net/datetime.formats.relative
4547
*/
@@ -48,6 +50,9 @@ public static function every(string|int|\DateInterval $frequency, object $messag
4850
return self::trigger(new PeriodicalTrigger($frequency, $from, $until), $message);
4951
}
5052

53+
/**
54+
* @param MessageProviderInterface|object $message A message provider that yields messages or a static message that will be dispatched on every trigger
55+
*/
5156
public static function cron(string $expression, object $message, \DateTimeZone|string $timezone = null): self
5257
{
5358
if (!str_contains($expression, '#')) {
@@ -62,15 +67,21 @@ public static function cron(string $expression, object $message, \DateTimeZone|s
6267
}
6368

6469
/**
65-
* @param MessageProviderInterface|object $message A message provider that yields messages or a static message that will be dispatched on every trigger.
70+
* @param MessageProviderInterface|object $message A message provider that yields messages or a static message that will be dispatched on every trigger
6671
*/
6772
public static function trigger(TriggerInterface $trigger, object $message): self
6873
{
6974
if ($message instanceof MessageProviderInterface) {
7075
return new self($trigger, $message);
7176
}
7277

73-
return new self($trigger, new CallbackMessageProvider(static fn (): array => [$message], $message instanceof \Stringable ? (string) $message : ''));
78+
try {
79+
$description = $message instanceof \Stringable ? (string) $message : serialize($message);
80+
} catch (\Exception) {
81+
$description = $message::class;
82+
}
83+
84+
return new self($trigger, new CallbackMessageProvider(static fn (): array => [$message], $description));
7485
}
7586

7687
public function withJitter(int $maxSeconds = 60): self

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ public function testYieldedContext()
130130

131131
public static function messagesProvider(): \Generator
132132
{
133-
$first = new Message(['id' => 'first']);
134-
$second = new Message(['id' => 'second']);
135-
$third = new Message(['id' => 'third']);
133+
$first = (object) ['id' => 'first'];
134+
$second = (object) ['id' => 'second'];
135+
$third = (object) ['id' => 'third'];
136136

137137
yield 'first' => [
138138
'startTime' => '22:12:00',
@@ -262,15 +262,3 @@ private static function makeDateTime(string $time): \DateTimeImmutable
262262
return new \DateTimeImmutable('2020-02-20T'.$time, new \DateTimeZone('UTC'));
263263
}
264264
}
265-
266-
class Message
267-
{
268-
public function __construct(private readonly array $data)
269-
{
270-
}
271-
272-
public function __toString(): string
273-
{
274-
return (string) spl_object_id($this);
275-
}
276-
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@
1616
final class CallbackMessageProvider implements MessageProviderInterface, \Stringable
1717
{
1818
private \Closure $callback;
19-
private string $description;
2019

2120
public function __construct(callable $callback, private string $description = '')
2221
{
2322
$this->callback = $callback(...);
24-
$this->description = $description;
2523
}
2624

2725
public function getMessages(MessageContext $context): iterable

0 commit comments

Comments
 (0)