CloudCastle Clock

🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano

PsrClockAdapter — PSR-20 clock adapter

Purpose

Wraps any Psr\Clock\ClockInterface into the package’s extended contract: adds timestamp(), microtime(), timezone(), freeze(), withTimezone().

What for and how to use

Smooth migration: clocks from another library (symfony, lcobucci...) work in all package APIs: PsrClockAdapter::wrap($foreign). A legacy non-PSR-20 object with a public now() returning any DateTimeInterface is accepted too.

Example

$foreign = new \Symfony\Component\Clock\NativeClock();
$clock = PsrClockAdapter::wrap($foreign);
$clock->timestamp();     // works on top of any PSR-20 clock

Anti-patterns

The adapter’s cheap primitives honestly materialise the inner clock’s moment — the native SystemClock is faster.

Lifecycle

flowchart LR
    A[Any PSR-20 clock] --> B[PsrClockAdapter]
    B --> C[Extended ClockInterface]
    C --> D[TimeSpan / Deadline / decorators]

Feature comparison with competitors

Aspect🏆 CloudCastlesymfonycarbonlcobuccibesteergebnis
Adapting any PSR-20 clock✅✅❌❌✅❌
Extended contract on top of PSR✅❌❌❌❌❌
Compatible with package decorators✅❌❌❌❌❌
freeze() snapshot of foreign clocks✅❌❌❌❌❌
Wrapping any object with a public now() (legacy)✅❌❌❌✅❌
Total🏆 510020

← Back to the feature list


🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano