minimum sample implementation of PSR-20

dev-main 2021-07-15 06:47 UTC

This package is auto-updated.

Last update: 2024-07-15 13:01:50 UTC


A minimal Sample-Implementation for PSR-20.

This tiny package allows you to inject a clock into your code that will either give you the current date and time (useful for production code) or a predefined one (useful for testing).


use Org_Heigl\Clock\FrozenClock;
use Org_Heigl\Clock\SystemClock;
use Psr\Clock\ClockInterface;

class App 
	public function main(ClockInterface $clock): string
	    return sprintf(
	        'The current date and time is %s', 
	        $clock->now()->format('Y-m-d H:i:s.u')

$app = new App();
$clock = new SystemClock();

var_Dump($app->main($clock) === $app->main($clock));
// This will most certainly be "false"

$clock = new FrozenClock(new DateTimeImmutable());
var_dump($app->main($clock) === $app->main($clock));
// This will always be true


Install the package via composer like this:

composer require org_heigl/clock