chamber-orchestra / doctrine-clock-bundle
The symfony doctrine clock bundle
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/chamber-orchestra/doctrine-clock-bundle
Requires
- php: ^8.4
- ext-intl: *
- chamber-orchestra/metadata-bundle: 8.0.*
- symfony/clock: 8.0.*
Requires (Dev)
- phpunit/phpunit: ^12.5
- symfony/test-pack: ^1.2
Conflicts
README
Doctrine Clock Bundle
A small Symfony bundle that integrates symfony/clock with Doctrine ORM. It provides timestamp traits, interfaces, and a Doctrine event subscriber that auto-populates createdDatetime and updatedDatetime fields using DatePoint.
Installation
composer require chamber-orchestra/doctrine-clock-bundle
If you are not using Symfony Flex, register the bundle manually:
// config/bundles.php return [ ChamberOrchestra\DoctrineClockBundle\ChamberOrchestraDoctrineClockBundle::class => ['all' => true], ];
Usage
Add timestamp fields to your Doctrine entities by using the provided traits and interfaces.
use ChamberOrchestra\DoctrineClockBundle\Contracts\Entity\TimestampInterface; use ChamberOrchestra\DoctrineClockBundle\Entity\TimestampTrait; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity] class Article implements TimestampInterface { use TimestampTrait; // ... your fields }
The subscriber will set createdDatetime on insert and updatedDatetime on insert/update. If you prefer precision with microseconds, use PrecisedTimestampTrait instead.
Custom DBAL Types (Optional)
The bundle includes DBAL type overrides for timestamp precision and decimal handling. If you want to use them, register them in Doctrine:
// config/packages/doctrine.php return [ 'dbal' => [ 'types' => [ 'datetime' => ChamberOrchestra\DoctrineClockBundle\Type\DateTimeType::class, 'datetime_immutable' => ChamberOrchestra\DoctrineClockBundle\Type\DateTimeImmutableType::class, 'decimal' => ChamberOrchestra\DoctrineClockBundle\Type\DecimalType::class, ], ], ];
Dependencies
- PHP 8.4+
symfony/clock8.0.*chamber-orchestra/metadata-bundle8.0.*
See composer.json for the full list.
Tests
composer test
This runs PHPUnit using phpunit.xml.dist.