arokettu / clock
PSR-20 Implementation
2.6.1
2024-09-06 16:29 UTC
Requires
- php: ^8.0
- arokettu/datetime-rounding: ^1.0
- arokettu/system-clock: ^2.0
- psr/clock: ^1.0
Requires (Dev)
- nesbot/carbon: ^2
- phpunit/phpunit: ^9
- psy/psysh: *
- sandfox.dev/code-standard: ^1.2024.07.20
- squizlabs/php_codesniffer: *
- vimeo/psalm: ^5
Provides
README
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
- RoundingClock. A clock wrapper that rounds time to a certain precision
- OffsetClock. A clock wrapper that modifies the inner clock by a given interval
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
Feel free to ask any questions in our room on Gitter: https://gitter.im/arokettu/community
License
The library is available as open source under the terms of the MIT License.