🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano
CallbackClock — callback clock
Purpose
The moment source is an arbitrary closure: a bridge to non-standard time sources (external service, scenario generator).
What for and how to use
Integrate a foreign time API or complex moment logic without writing your own clock class.
Example
$clock = new CallbackClock(
fn (): DateTimeImmutable => $externalTimeService->current(),
'UTC',
);
Anti-patterns
The closure must be fast and side-effect free — it runs on every read.
Lifecycle
flowchart LR
A[Closure] -->|DateTimeImmutable| B[CallbackClock]
B --> C[ClockInterface consumers]
Feature comparison with competitors
| Aspect | 🏆 CloudCastle | symfony | carbon | lcobucci | beste | ergebnis |
|---|---|---|---|---|---|---|
| Arbitrary moment source | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Declared timezone | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Full package clock contract | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Closure instead of inheritance | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Total | 🏆 4 | 0 | 0 | 0 | 0 | 0 |
🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano