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

Skip to content

[Scheduler] Add the possibility to override the default CallbackTrigger description #50132

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

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Scheduler\Tests\Trigger;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Scheduler\Trigger\CallbackTrigger;

class CallbackTriggerTest extends TestCase
{
public function testToString()
{
$trigger = new CallbackTrigger(fn () => null);
$this->assertMatchesRegularExpression('/^\d{32}$/', (string) $trigger);

$trigger = new CallbackTrigger(fn () => null, '');
$this->assertSame('', (string) $trigger);

$trigger = new CallbackTrigger(fn () => null, 'foo');
$this->assertSame('foo', (string) $trigger);
}
}
6 changes: 4 additions & 2 deletions src/Symfony/Component/Scheduler/Trigger/CallbackTrigger.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@
final class CallbackTrigger implements TriggerInterface
{
private \Closure $callback;
private string $description;

public function __construct(callable $callback)
public function __construct(callable $callback, string $description = null)
{
$this->callback = $callback(...);
$this->description = $description ?? spl_object_hash($this->callback);
}

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

public function getNextRunDate(\DateTimeImmutable $run): ?\DateTimeImmutable
Expand Down