Skip to content

joubertredrat/entity-datetime

Repository files navigation

Entity datetime

Build Status Scrutinizer Code Quality Build Status Code Coverage Latest Stable Version Total Downloads License

Trait for easy manage useful datetime in entities.

Install

Install by composer

composer require redrat/entity-datetime

Usage

With Doctrine

1 - Add trait in your Entity

<?php

use RedRat\Entity\DateTimeTrait;

class Foo
{
    use DateTimeTrait;
}

2 - Set lifecycleCallbacks in your Doctrine configuration, like example below:

    fields:
        createdAt:
            type: datetime
        updatedAt:
            type: datetime
            nullable: true
            
    lifecycleCallbacks:
        prePersist: [ forgeCreatedAt ]
        preUpdate: [ forgeUpdatedAt ]

Note: More about lifecycle callbacks in Doctrine documentation.

TODO

  • API documentation.