Download the PHP package andanteproject/timestampable-bundle without Composer
On this page you can find all versions of the php package andanteproject/timestampable-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download andanteproject/timestampable-bundle
More information about andanteproject/timestampable-bundle
Files in andanteproject/timestampable-bundle
Package timestampable-bundle
Short Description A Symfony Bundle to handle entities createdAt and updatedAt dates with Doctrine
License MIT
Informations about the package timestampable-bundle
Timestampable Bundle
Symfony Bundle - AndanteProject
A Symfony Bundle to handle entities createdAt and updatedAt dates with Doctrine. 🕰
Requirements
Symfony 4.x-7.x and PHP 8.2.
Install
Via Composer:
Features
- No configuration required to be ready to go but fully customizabile;
createdAt
andupdatedAt
properties are?\DateTimeImmutable
;- Uses Symfony Clock;
- Does not override your
createdAt
andupdatedAt
values when you set them explicitly; - No annotation/attributes required;
- Works like magic ✨.
Basic usage
After install, make sure you have the bundle registered in your symfony bundles list (config/bundles.php
):
This should have been done automagically if you are using Symfony Flex. Otherwise, just register it by yourself.
Let's suppose we have a App\Entity\Article
doctrine entity we want to track created and update dates.
All you have to do is to implement Andante\TimestampableBundle\Timestampable\TimestampableInterface
and use Andante\TimestampableBundle\Timestampable\TimestampableTrait
trait.
Make sure to update you database schema following your doctrine workflow (bin/console doctrine:schema:update --force
if you are a badass devil guy or with a migration if you choosed the be a better developer!).
You shoud see a new columns named created_at
and updated_at
(doctrine naming strategy.
Congrats! You're done! 🎉
Remember that TimestampableInterface
and TimestampableTrait
are shortcut to use CreatedAtTimestampableInterface
+CreatedAtTimestampableTrait
and UpdatedAtTimestampableInterface
+UpdatedAtTimestampableTrait
at the same time!
If you need to track only create date or update date you can use these more specific interfaces!
To keep track of | Implement interface | Use this Trait |
---|---|---|
Create date | Andante\TimestampableBundle\Timestampable\CreatedAtTimestampableInterface |
Andante\TimestampableBundle\Timestampable\CreatedAtTimestampableTrait |
Update date | Andante\TimestampableBundle\Timestampable\UpdatedAtTimestampableInterface |
Andante\TimestampableBundle\Timestampable\UpdatedAtTimestampableTrait |
Both create and update dates | Andante\TimestampableBundle\Timestampable\TimestampableInterface |
Andante\TimestampableBundle\Timestampable\TimestampableTrait |
Usage with no trait
This allows you to, for instance, to have a different name for your properties (E.g. created
instead of createdAt
and updated
instead of updatedAt
).
But you will need to explicit this in bundle configuration.
Configuration (completely optional)
This bundle is build thinking how to save you time and follow best practices as close as possible.
This means you can even ignore to have a andante_timestampable.yml
config file in your application.
However, for whatever reason (legacy code?), use the bundle configuration to change most of the behaviors as your needs.
Built with love ❤️ by AndanteProject team.
All versions of timestampable-bundle with dependencies
symfony/framework-bundle Version ^5.0 | ^6.0 | ^7.0
doctrine/common Version ^2.13 || ^3.0
doctrine/event-manager Version ^1.2 | ^2.0
symfony/clock Version ^6.2 | ^7.0