redrat/entity-datetime

Datetime trait for entities

0.2.0 2019-10-10 21:15 UTC

This package is auto-updated.

Last update: 2024-10-28 13:42:07 UTC


README

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.