andanteproject/timestampable-bundle
Symfony bundle for Doctrine entities that automatically manages createdAt and updatedAt with DateTimeImmutable. Zero config to start, customizable, uses Symfony Clock, no attributes needed, and won’t overwrite timestamps you set manually. Compatible with Symfony 5–8, PHP 8.2.
createdAt/updatedAt fields. The trait-based implementation mirrors Laravel’s HasTimestamps trait, easing migration paths.DateTime pitfalls.TimestampableInterface and use the trait. This mirrors Laravel’s HasTimestamps but with Symfony’s type safety (DateTimeImmutable).symfony/clock for time handling) or by wrapping the bundle in a Laravel service provider.metadata_cache_warmer_enabled in production may introduce cache invalidation complexity (e.g., post-deploy warmup scripts). Mitigate by testing in staging with cache:clear --no-warmup.Gedmo\Timestampable) require explicit configuration or disabling one of them.HasTimestamps entirely, or coexist in a hybrid app?DateTimeImmutable handling) in a Laravel package (e.g., spatie/laravel-timestamps alternative).created_at fields, Gedmo).setCreatedAt() logic).App\Entity\LogEntry).TimestampableTrait to new entities.schema:update --force for new columns.// src/Migration/Version20231001000000.php
public function up(SchemaManager $sm): void
{
$sm->addColumn('article', 'created_at', 'datetime_immutable');
$sm->addColumn('article', 'updated_at', 'datetime_immutable');
}
snake_case vs. camelCase).Gedmo\Timestampable) require priority configuration or disabling one bundle.config/app.timezone.pdo and ctype (standard in PHP 8.2+). No additional extensions needed.composer require andanteproject/timestampable-bundle symfony/clock
config/bundles.php.TimestampableInterface and add TimestampableTrait.use Andante\TimestampableBundle\Timestampable\{TimestampableInterface, TimestampableTrait};
#[ORM\Entity]
class Article implements TimestampableInterface
{
use TimestampableTrait;
// ...
}
entity->setCreatedAt(new DateTimeImmutable())).metadata_cache_warmer_enabled in config/packages/andante_timestampable.yaml for production:
andante_timestampable:
metadata_cache_warmer_enabled: true
php bin/console cache:warmup --env=prod
andante_timestampable.yaml reduces per-entity maintenance.bin/console debug:container Andante\TimestampableBundle to inspect services.%kernel.cache_dir%/timestampable_metadata.php for issues.prePersist listeners).cache:clear) or enable warmup.| Scenario | Impact | Mitigation |
|---|---|---|
| Metadata cache corruption | Broken timestamping | Disable warmup; rely on lazy build. |
| Doctrine event conflict | Timestamps ignored/overwritten | Adjust listener priority. |
| Database schema mismatch | created_at column missing |
Use migrations; validate schema. |
| Time provider failure | Invalid timestamps (e.g., null) | Fallback to new DateTimeImmutable() in custom logic. |
| PHP 8.2+ requirement | Incompatible with older Laravel | Use polyfills or target newer stacks. |
How can I help you explore Laravel packages today?