Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Scheduler] AddAbstractTriggerDecorator#51152

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:6.4fromkbond:decorated-trigger
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes fromall 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
1 change: 1 addition & 0 deletionssrc/Symfony/Component/Scheduler/CHANGELOG.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@ CHANGELOG
---

* Allow setting timezone of next run date in CronExpressionTrigger
* Add `AbstractTriggerDecorator`

6.3
---
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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\ExcludeTimeTrigger;
use Symfony\Component\Scheduler\Trigger\JitterTrigger;
use Symfony\Component\Scheduler\Trigger\TriggerInterface;

class AbstractDecoratedTriggerTest extends TestCase
{
public function testCanGetInnerTrigger()
{
$trigger = new JitterTrigger($inner = $this->createMock(TriggerInterface::class));

$this->assertSame($inner, $trigger->inner());
$this->assertSame([$trigger], iterator_to_array($trigger->decorators()));
}

public function testCanGetNestedInnerTrigger()
{
$trigger = new ExcludeTimeTrigger(
$jitter = new JitterTrigger($inner = $this->createMock(TriggerInterface::class)),
new \DateTimeImmutable(),
new \DateTimeImmutable(),
);

$this->assertSame($inner, $trigger->inner());
$this->assertSame([$trigger, $jitter], iterator_to_array($trigger->decorators()));
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
<?php

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

namespace Symfony\Component\Scheduler\Trigger;

/**
* @author Kevin Bond <kevinbond@gmail.com>
*/
abstract class AbstractDecoratedTrigger implements TriggerInterface
{
public function __construct(private TriggerInterface $inner)
{
}

final public function inner(): TriggerInterface
{
$inner = $this->inner;

while ($inner instanceof self) {
$inner = $inner->inner;
}

return $inner;
}

/**
* @return \Traversable<self>
*/
final public function decorators(): \Traversable
{
yield $this;

$inner = $this->inner;

while ($inner instanceof self) {
yield $inner;

$inner = $inner->inner;
}
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,13 +14,14 @@
/**
* @experimental
*/
final class ExcludeTimeTriggerimplements TriggerInterface
final class ExcludeTimeTriggerextends AbstractDecoratedTrigger
{
public function __construct(
private readonly TriggerInterface $inner,
private readonly \DateTimeImmutable $from,
private readonly \DateTimeImmutable $until,
) {
parent::__construct($inner);
}

public function __toString(): string
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,13 +14,14 @@
/**
* @author Kevin Bond <kevinbond@gmail.com>
*/
final class JitterTriggerimplements TriggerInterface
final class JitterTriggerextends AbstractDecoratedTrigger
{
/**
* @param positive-int $maxSeconds
*/
public function __construct(private readonly TriggerInterface $trigger, private readonly int $maxSeconds = 60)
{
parent::__construct($trigger);
}

public function __toString(): string
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,7 +16,7 @@
/**
* @experimental
*/
class PeriodicalTrigger implements TriggerInterface, \Stringable
class PeriodicalTrigger implements TriggerInterface
{
private float $intervalInSeconds = 0.0;
private \DateTimeImmutable $from;
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp