You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Go to file
Anton Smirnov fc43a65947 Changelog for 2.2.0 6 days ago
docs Merge branch '1.x' 6 days ago
src Merge branch '1.x' 6 days ago
tests Update code style 2 months ago
.gitattributes Add gitattributes 3 months ago
.gitignore Docs 3 months ago
.gitlab-ci.yml Do not build in PHP 7 3 months ago
CHANGELOG.md Changelog for 2.2.0 6 days ago
LICENSE.md License and changelog 3 months ago
README.md Merge branch '1.x' 6 days ago
composer.json Merge branch '1.x' 6 days ago
phpcs.xml Bump language level to 8.0 and remove mutable hack 3 months ago
phpunit.xml Deduplicate SystemClock, just use arokettu/system-clock 6 days ago
psalm.xml Remove the helper 3 months ago

README.md

Clock

Packagist PHP Packagist Gitlab pipeline status Codecov

A collection of clock abstraction classes for PSR-20.

Installation

composer require arokettu/clock

Supported versions:

  • 1.x (LTS-ish, PHP 7.0+)
  • 2.x (current, PHP 8.0+)

Example

<?php

$clock = new \Arokettu\Clock\SystemClock();
$clockPsrAwareValidator->isValid($clock);

For a specific example, lcobucci/jwt:

<?php

use Arokettu\Clock\SystemClock;
use Lcobucci\JWT\Configuration;
use Lcobucci\JWT\Signer\Hmac\Sha256;

$cfg = Configuration::forSymmetricSigner(new Sha256(), '...');
$token = $cfg->parser()->parse('...');

$cfg->validator()->assert(
    $token,
    new StrictValidAt(new SystemClock())
);

Documentation

Available clock classes:

  • SystemClock. Plain class that returns operating system clock, also available as a separate package: arokettu/system-clock
  • ShiftedClock. System clock + fixed interval
  • StaticClock. Clock that returns a single set value
  • MutableClock. Based on mutable DateTime class
  • TickingClock. Clock that advances an interval every call
  • CallbackClock. A wrapper for a closure that also supports generator closures

Read full documentation here: https://sandfox.dev/php/clock.html

Also on Read the Docs: https://arokettu-clock.readthedocs.io/

Support

Please file issues on our main repo at GitLab: https://gitlab.com/sandfox/php-clock/-/issues

License

The library is available as open source under the terms of the MIT License.