承接 tourze/doctrine-timestamp-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tourze/doctrine-timestamp-bundle

Composer 安装命令:

composer require tourze/doctrine-timestamp-bundle

包简介

Symfony Bundle for automatic timestamp management in Doctrine entities

README 文档

README

English | 中文

Latest Version PHP Version License Build Status Code Coverage

A Symfony bundle that automatically manages creation and update timestamps for Doctrine entities via PHP attributes.

Features

  • Automatically sets creation timestamp on persist
  • Automatically updates modification timestamp on update
  • Supports both DateTime and Unix timestamp formats
  • Configuration via PHP 8.1 attributes
  • Zero configuration: just add attributes to your entity fields
  • Compatible with Doctrine ORM and Symfony 6.4+

Installation

composer require tourze/doctrine-timestamp-bundle

Requirements

  • PHP >= 8.1
  • Symfony >= 6.4
  • doctrine/doctrine-bundle >= 2.13

Quick Start

Add attributes to your entity

use Tourze\DoctrineTimestampBundle\Attribute\CreateTimeColumn;
use Tourze\DoctrineTimestampBundle\Attribute\UpdateTimeColumn;
use Tourze\DoctrineTimestampBundle\Enum\Types;

class YourEntity
{
    #[CreateTimeColumn(type: Types::datetime)]
    private DateTime $createdAt;

    #[UpdateTimeColumn(type: Types::timestamp)]
    private int $updatedAt;
}
  • Types::datetime: stores as DateTime object (default)
  • Types::timestamp: stores as Unix timestamp

No further configuration is needed. The bundle will automatically set these fields during persist and update events.

Configuration

Bundle Registration

If using Symfony Flex, the bundle is auto-registered. Otherwise, add to config/bundles.php:

return [
    // ...
    Tourze\DoctrineTimestampBundle\DoctrineTimestampBundle::class => ['all' => true],
];

Service Configuration

The bundle automatically registers its services. No additional configuration required.

Logging (Optional)

To enable debug logging for timestamp operations, configure your logger:

# config/packages/monolog.yaml (dev environment)
monolog:
    handlers:
        main:
            level: debug
            channels: ["!doctrine.timestamp"]

Documentation

Attributes

  • CreateTimeColumn: Marks a property as the creation timestamp
  • UpdateTimeColumn: Marks a property as the update timestamp
  • Both accept an optional type parameter: Types::datetime or Types::timestamp

Event Subscriber

  • The bundle registers a Doctrine event subscriber (TimeListener) that listens to prePersist and preUpdate events.
  • On entity creation, if the field is empty, sets the current time.
  • On entity update, if the field is not manually changed, updates the time.

Advanced Usage

  • You can use either DateTime or int (timestamp) as your property type.
  • Works with property accessor for flexible entity property handling.

Convenience Traits

The bundle provides ready-to-use traits for common scenarios:

use Tourze\DoctrineTimestampBundle\Traits\CreateTimeAware;
use Tourze\DoctrineTimestampBundle\Traits\TimestampableAware;

// Only creation timestamp
class ReadOnlyEntity
{
    use CreateTimeAware;
    // Provides: $createTime property with getter/setter
}

// Both creation and update timestamps
class MutableEntity
{
    use TimestampableAware;
    // Provides: $createTime and $updateTime properties with getters/setters
    // Also includes: retrieveTimestampArray() method
}

These traits use DateTimeImmutable type and are automatically handled by the bundle.

Security

Timestamp Integrity

  • Timestamps are set automatically by the bundle and cannot be manually overridden during normal operations
  • The bundle respects existing values if manually set before persistence
  • All timestamp operations are logged at debug level for audit purposes

Best Practices

  • Use DateTimeImmutable for better immutability guarantees
  • Consider timezone implications when storing timestamps
  • Validate timestamp ranges in your application logic if needed

Contribution Guide

  • Please submit issues and pull requests via GitHub.
  • Code style: PSR-12
  • Run tests and static analysis before submitting PRs.
  • See CONTRIBUTING.md if available.

License

MIT License. See LICENSE for details.

Author

tourze https://github.com/tourze

Changelog

See CHANGELOG.md for version history and upgrade notes.

tourze/doctrine-timestamp-bundle 适用场景与选型建议

tourze/doctrine-timestamp-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 38.38k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 03 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 tourze/doctrine-timestamp-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 tourze/doctrine-timestamp-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 tourze/doctrine-timestamp-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 38.38k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 27
  • 依赖项目数: 164
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-25