diff --git a/composer.json b/composer.json index 94e67869f..3d366c4fc 100644 --- a/composer.json +++ b/composer.json @@ -22,6 +22,7 @@ "php": "~8.1.0", "doctrine/dbal": "^3.4.2", "psr/cache": "^2.0.0|^3.0.0", + "psr/clock": "^1.0", "psr/log": "^2.0.0|^3.0.0", "psr/simple-cache": "^2.0.0|^3.0.0", "symfony/console": "^5.4.1|^6.0.1", diff --git a/composer.lock b/composer.lock index 07706667c..a69f10e49 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e31c22c41617409f8ac2de2229b46bf2", + "content-hash": "9c67971791afc85eb133c6de106862ad", "packages": [ { "name": "doctrine/cache", @@ -394,6 +394,54 @@ }, "time": "2021-02-03T23:26:27+00:00" }, + { + "name": "psr/clock", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/clock.git", + "reference": "e41a24703d4560fd0acb709162f73b8adfc3aa0d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/clock/zipball/e41a24703d4560fd0acb709162f73b8adfc3aa0d", + "reference": "e41a24703d4560fd0acb709162f73b8adfc3aa0d", + "shasum": "" + }, + "require": { + "php": "^7.0 || ^8.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Psr\\Clock\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for reading the clock.", + "homepage": "https://github.com/php-fig/clock", + "keywords": [ + "clock", + "now", + "psr", + "psr-20", + "time" + ], + "support": { + "issues": "https://github.com/php-fig/clock/issues", + "source": "https://github.com/php-fig/clock/tree/1.0.0" + }, + "time": "2022-11-25T14:36:26+00:00" + }, { "name": "psr/container", "version": "2.0.2", @@ -7547,5 +7595,5 @@ "platform-dev": { "ext-pdo_sqlite": "~8.1.0" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.2.0" } diff --git a/docs/pages/clock.md b/docs/pages/clock.md index ff13feabb..09a3dbc9a 100644 --- a/docs/pages/clock.md +++ b/docs/pages/clock.md @@ -5,7 +5,7 @@ purposes. We are using this clock to create the `recorded_on` datetime for the e !!! note - The `Clock` interface will be PSR-20 compatible as soon at it is published. For more information see [here](https://github.com/php-fig/fig-standards/blob/master/proposed/clock.md). + The `Clock` interface is PSR-20 compatible. For more information see [here](https://github.com/php-fig/fig-standards/blob/master/proposed/clock.md). ## SystemClock diff --git a/src/Clock/Clock.php b/src/Clock/Clock.php index 3b8da6ca3..ddb52b255 100644 --- a/src/Clock/Clock.php +++ b/src/Clock/Clock.php @@ -4,9 +4,8 @@ namespace Patchlevel\EventSourcing\Clock; -use DateTimeImmutable; +use Psr\Clock\ClockInterface; -interface Clock +interface Clock extends ClockInterface { - public function now(): DateTimeImmutable; } diff --git a/src/EventBus/Decorator/RecordedOnDecorator.php b/src/EventBus/Decorator/RecordedOnDecorator.php index 9f9a2dd47..a9c091f22 100644 --- a/src/EventBus/Decorator/RecordedOnDecorator.php +++ b/src/EventBus/Decorator/RecordedOnDecorator.php @@ -4,13 +4,14 @@ namespace Patchlevel\EventSourcing\EventBus\Decorator; -use Patchlevel\EventSourcing\Clock\Clock; use Patchlevel\EventSourcing\EventBus\Message; +use Psr\Clock\ClockInterface; final class RecordedOnDecorator implements MessageDecorator { - public function __construct(private readonly Clock $clock) - { + public function __construct( + private readonly ClockInterface $clock + ) { } public function __invoke(Message $message): Message