PHPackages                             tourze/doctrine-timestamp-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. tourze/doctrine-timestamp-bundle

ActiveLibrary

tourze/doctrine-timestamp-bundle
================================

Symfony Bundle for automatic timestamp management in Doctrine entities

1.1.0(6mo ago)037.9k20MITPHPCI passing

Since Mar 25Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tourze/doctrine-timestamp-bundle)[ Packagist](https://packagist.org/packages/tourze/doctrine-timestamp-bundle)[ RSS](/packages/tourze-doctrine-timestamp-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (26)Versions (12)Used By (20)

Doctrine Timestamp Bundle
=========================

[](#doctrine-timestamp-bundle)

[English](README.md) | [中文](README.zh-CN.md)

[![Latest Version](https://camo.githubusercontent.com/7ad72efaaae01a4d3728fbb5f85a97ba1c4429c8b97a475a0fecaa8b45a9cd20/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f646f637472696e652d74696d657374616d702d62756e646c652e737667)](https://packagist.org/packages/tourze/doctrine-timestamp-bundle)[![PHP Version](https://camo.githubusercontent.com/74e83818a6af241d3cedb32b9763b6308a3151cf0e857c186dcf0043224cedc1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f646f637472696e652d74696d657374616d702d62756e646c652e737667)](https://packagist.org/packages/tourze/doctrine-timestamp-bundle)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![Build Status](https://camo.githubusercontent.com/dbc4c234b51e6ac8fdd1ead1cb1ef0a131b9a3b6434968e2ae92d0c54dab3af7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746f75727a652f646f637472696e652d74696d657374616d702d62756e646c652f63692e796d6c)](https://github.com/tourze/doctrine-timestamp-bundle/actions)[![Code Coverage](https://camo.githubusercontent.com/8f58ff0d690896797636d811614b473af5ea54a264031be4e68c56541a79641d/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f75727a652f646f637472696e652d74696d657374616d702d62756e646c65)](https://codecov.io/gh/tourze/doctrine-timestamp-bundle)

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

---

Features
--------

[](#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
------------

[](#installation)

```
composer require tourze/doctrine-timestamp-bundle
```

### Requirements

[](#requirements)

- PHP &gt;= 8.1
- Symfony &gt;= 6.4
- doctrine/doctrine-bundle &gt;= 2.13

Quick Start
-----------

[](#quick-start)

### Add attributes to your entity

[](#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
-------------

[](#configuration)

### Bundle Registration

[](#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

[](#service-configuration)

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

### Logging (Optional)

[](#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
-------------

[](#documentation)

### Attributes

[](#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

[](#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

[](#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

[](#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
--------

[](#security)

### Timestamp Integrity

[](#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

[](#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
------------------

[](#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](CONTRIBUTING.md) if available.

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) for details.

Author
------

[](#author)

tourze

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for version history and upgrade notes.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance72

Regular maintenance activity

Popularity22

Limited adoption so far

Community25

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~22 days

Recently: every ~35 days

Total

11

Last Release

189d ago

Major Versions

0.0.9 → 1.0.02025-10-31

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (5 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-doctrine-timestamp-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-doctrine-timestamp-bundle/health.svg)](https://phpackages.com/packages/tourze-doctrine-timestamp-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M650](/packages/sylius-sylius)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[contao/core-bundle

Contao Open Source CMS

1231.6M2.3k](/packages/contao-core-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
