🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano
PsrClockAdapter — adaptateur d’horloge PSR-20
Objectif
Encapsule n’importe quelle Psr\Clock\ClockInterface dans le contrat étendu du paquet : ajoute timestamp(), microtime(), timezone(), freeze(), withTimezone().
À quoi ça sert et comment l’utiliser
Migration en douceur : une horloge issue d’une autre bibliothèque (symfony, lcobucci...) fonctionne dans toutes les API du paquet : PsrClockAdapter::wrap($foreign).
Exemple
$foreign = new \Symfony\Component\Clock\NativeClock();
$clock = PsrClockAdapter::wrap($foreign);
$clock->timestamp(); // works on top of any PSR-20 clock
Anti-modèles
Les primitives économiques de l’adaptateur matérialisent honnêtement l’instant de l’horloge interne — la SystemClock native est plus rapide.
Cycle de vie
flowchart LR
A[Any PSR-20 clock] --> B[PsrClockAdapter]
B --> C[Extended ClockInterface]
C --> D[TimeSpan / Deadline / decorators]
Comparaison des fonctionnalités avec les concurrents
| Aspect | 🏆 CloudCastle | symfony | carbon | lcobucci | beste | ergebnis |
|---|---|---|---|---|---|---|
| Adaptation de n’importe quelle horloge PSR-20 | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ |
| Contrat étendu par-dessus PSR | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Compatible avec les décorateurs du paquet | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
Instantané freeze() d’horloges tierces | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
Encapsulation de tout objet doté d’un now() public (legacy) | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ |
| Total | 🏆 5 | 1 | 0 | 0 | 2 | 0 |
← Retour à la liste des fonctionnalités
🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano