| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\Clock; |
| 13 |
|
| 14 |
use Psr\Clock\ClockInterface; |
| 15 |
use Symfony\Contracts\Service\Attribute\Required; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
trait ClockAwareTrait |
| 23 |
{ |
| 24 |
private readonly ClockInterface $clock; |
| 25 |
|
| 26 |
#[Required] |
| 27 |
public function setClock(ClockInterface $clock): void |
| 28 |
{ |
| 29 |
$this->clock = $clock; |
| 30 |
} |
| 31 |
|
| 32 |
protected function now(): DatePoint |
| 33 |
{ |
| 34 |
$now = ($this->clock ??= new Clock())->now(); |
| 35 |
|
| 36 |
return $now instanceof DatePoint ? $now : DatePoint::createFromInterface($now); |
| 37 |
} |
| 38 |
} |