Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ClockServiceProvider | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| getFactories | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| getExtensions | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * This file is part of php-fast-forward/clock. |
| 7 | * |
| 8 | * This source file is subject to the license bundled |
| 9 | * with this source code in the file LICENSE. |
| 10 | * |
| 11 | * @copyright Copyright (c) 2025-2026 Felipe Sayão Lobato Abreu <github@mentordosnerds.com> |
| 12 | * @license https://opensource.org/licenses/MIT MIT License |
| 13 | * |
| 14 | * @see https://github.com/php-fast-forward/clock |
| 15 | * @see https://github.com/php-fast-forward |
| 16 | * @see https://datatracker.ietf.org/doc/html/rfc2119 |
| 17 | */ |
| 18 | |
| 19 | namespace FastForward\Clock\ServiceProvider; |
| 20 | |
| 21 | use DateTimeZone; |
| 22 | use FastForward\Clock\ServiceProvider\Factory\DateTimeZoneFactory; |
| 23 | use FastForward\Clock\SystemClock; |
| 24 | use FastForward\Container\Factory\AliasFactory; |
| 25 | use FastForward\Container\Factory\InvokableFactory; |
| 26 | use Interop\Container\ServiceProviderInterface; |
| 27 | use Psr\Clock\ClockInterface; |
| 28 | |
| 29 | /** |
| 30 | * Registers Symfony Clock services for Fast Forward Container. |
| 31 | */ |
| 32 | /** |
| 33 | * Service provider for registering Symfony Clock services in the Fast Forward Container. |
| 34 | * |
| 35 | * This class SHALL expose factories and extensions for clock-related services, including |
| 36 | * PSR-20 and Symfony Clock implementations, using the Fast Forward Container conventions. |
| 37 | * |
| 38 | * @see https://github.com/php-fast-forward/clock |
| 39 | * @see https://github.com/php-fast-forward |
| 40 | * @see https://datatracker.ietf.org/doc/html/rfc2119 |
| 41 | */ |
| 42 | class ClockServiceProvider implements ServiceProviderInterface |
| 43 | { |
| 44 | /** |
| 45 | * Returns the service factories exposed by this package. |
| 46 | * |
| 47 | * The returned array SHALL map service names (class strings) to callables or factory objects |
| 48 | * that create the corresponding service instances. This includes: |
| 49 | * |
| 50 | * - DateTimeZone::class: Provides a DateTimeZone instance using DateTimeZoneFactory. |
| 51 | * - ClockInterface::class and SymfonyClockInterface::class: Aliases to NativeClock. |
| 52 | * - NativeClock, MockClock, MonotonicClock: Instantiated via InvokableFactory with appropriate arguments. |
| 53 | * |
| 54 | * @see https://github.com/php-fast-forward/clock |
| 55 | * |
| 56 | * @return array<string, callable> associative array of service factories |
| 57 | */ |
| 58 | public function getFactories(): array |
| 59 | { |
| 60 | return [ |
| 61 | ClockInterface::class => AliasFactory::get(SystemClock::class), |
| 62 | SystemClock::class => new InvokableFactory(SystemClock::class, DateTimeZone::class), |
| 63 | DateTimeZone::class => new DateTimeZoneFactory(), |
| 64 | ]; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Returns the service extensions exposed by this package. |
| 69 | * |
| 70 | * The returned array SHALL map service names (class strings) to callables that extend or decorate |
| 71 | * existing services. This implementation returns an empty array, as no extensions are provided by default. |
| 72 | * |
| 73 | * @see https://github.com/php-fast-forward/clock |
| 74 | * |
| 75 | * @return array<string, callable> associative array of service extensions (empty by default) |
| 76 | */ |
| 77 | public function getExtensions(): array |
| 78 | { |
| 79 | return []; |
| 80 | } |
| 81 | } |