chamber-orchestra/doctrine-clock-bundle
prePersist/preUpdate logic, aligning with modern Symfony’s attribute-driven architecture.TimestampableInterface) with PHP 8.4 attributes (#[CreateTimestamp], #[UpdateTimestamp]), reducing boilerplate and improving IDE support (autocompletion, refactoring).#[CreateTimestamp] private ?\DateTimeImmutable $createdAt). No changes to existing prePersist/preUpdate lifecycle callbacks or repository methods.symfony/clock) and PHP 8.4 (for attributes). Risk: Legacy Symfony 6.x/7.x apps would need upgrades or alternative solutions (e.g., manual timestamps or stof/doctrine-extensions).prePersist logic) unless sequenced properly.| Risk Area | Mitigation Strategy |
|---|---|
| Clock Component | Ensure Symfony 8.0+ (or backport Clock to 7.x if critical). Test with symfony/clock:^1.0. |
| Attribute Reflection | PHP 8.4+ required; verify runtime compatibility (e.g., php -r "echo PHP_VERSION;"). |
| Event Subscriber Order | Override Doctrine event dispatcher order if conflicts arise (e.g., via priority in config). |
| Time Zone Handling | Explicitly configure symfony/clock’s time zone (default: system time zone). |
| Performance | Attributes add minimal overhead; benchmark in high-write scenarios. |
prePersist/preUpdate methods that might conflict?stof/doctrine-extensions: Legacy trait-based approach (less modern).new \DateTime() calls).Phase 1: Attribute Adoption
use TimestampableInterface) with attributes:
#[CreateTimestamp]
#[UpdateTimestamp]
private ?\DateTimeImmutable $createdAt;
Phase 2: Configuration
composer.json:
"require": {
"chamber-orchestra/doctrine-clock-bundle": "^1.0"
}
config/bundles.php:
ChamberOrchestra\DoctrineClockBundle\DoctrineClockBundle::class => ['all' => true],
config/packages/doctrine_clock.yaml:
doctrine_clock:
time_zone: 'UTC'
Phase 3: Testing
createdAt auto-populated).updatedAt refreshed).null timestamps, concurrent writes).prePersist logic doesn’t break (may need reordering).symfony/clock:^1.0 compatibility (check for breaking changes).DateTimeImmutable alternatives (e.g., Carbon), ensure the bundle’s Type system supports them.User, Order) after validating the bundle’s behavior.prePersist/preUpdate methods across entities.debug:event-dispatcher).opcache.revalidate_freq).symfony/clock configuration and system time zone.README.md; may need internal runbooks for:
null timestamps.| Scenario | Impact | Mitigation |
|---|---|---|
| Bundle Disabled | No timestamps set. | Fallback to manual prePersist logic. |
| Clock Component Bug | Incorrect timestamps. | Pin to a stable symfony/clock version. |
| PHP 8.4 Attribute Issue | Attributes ignored. | Downgrade to PHP 8.3 with a polyfill (e.g., ramsey/attributes). |
| Doctrine Event Conflict | Timestamps overridden. | Adjust subscriber priority in config. |
| Time Zone Mismatch | Inconsistent timestamps. | Explicitly set time_zone in config. |
#[CreateTimestamp]).ClockInterface).dd($entity->getCreatedAt())).phpunit.xml).DoctrineClockBundle warnings/errors.createdAt vs. now() skew).How can I help you explore Laravel packages today?