Files
drmaterac.pl/modules/pshowsso/deps/lcobucci/jwt/compat/lcobucci-clock-polyfill.php
Jacek Pyziak 778ee26fe4 Add Symfony Deprecation Contracts package
- Created CHANGELOG.md to maintain version history.
- Added README.md with usage instructions for the trigger_deprecation() function.
- Initialized composer.json for the Symfony Deprecation Contracts library, specifying dependencies and autoloading.
2025-12-15 08:43:18 +01:00

71 lines
1.5 KiB
PHP

<?php
namespace PShowSsoScoped\Lcobucci\Clock;
use DateTimeImmutable;
use DateTimeZone;
use function interface_exists;
if (! interface_exists(Clock::class)) {
interface Clock
{
/** @return DateTimeImmutable */
public function now();
}
final class FrozenClock implements Clock
{
/** @var DateTimeImmutable */
private $now;
public function __construct(DateTimeImmutable $now)
{
$this->now = $now;
}
/** @return self */
public static function fromUTC()
{
return new self(new DateTimeImmutable('now', new DateTimeZone('UTC')));
}
public function setTo(DateTimeImmutable $now)
{
$this->now = $now;
}
public function now()
{
return $this->now;
}
}
final class SystemClock implements Clock
{
/** @var DateTimeZone */
private $timezone;
public function __construct(DateTimeZone $timezone)
{
$this->timezone = $timezone;
}
/** @return self */
public static function fromUTC()
{
return new self(new DateTimeZone('UTC'));
}
/** @return self */
public static function fromSystemTimezone()
{
return new self(new DateTimeZone(date_default_timezone_get()));
}
public function now()
{
return new DateTimeImmutable('now', $this->timezone);
}
}
}