chamber-orchestra/doctrine-clock-bundle
最新稳定版本:v8.0.1
Composer 安装命令:
composer require chamber-orchestra/doctrine-clock-bundle
包简介
The symfony doctrine clock bundle
README 文档
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.
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04