2017 © Pedro Pelรกez
 

library timestamps

Automatic createdAt and updatedAt properties

image

harp-orm/timestamps

Automatic createdAt and updatedAt properties

  • Friday, July 11, 2014
  • by hkdobrev
  • Repository
  • 2 Watchers
  • 1 Stars
  • 103 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Timestamps

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version, (*1)

Automatic createdAt and updatedAt properties, (*2)

Usage

Add the triats to the Repo and Model classes:, (*3)

use Harp\Harp\AbstractModel;
use Harp\Timestamps\TimestampsTrait;

class User extends AbstractModel
{
    use TimestampsTrait;

    public static function initialize($config)
    {
        // Adds events to populate the properties
        TimestampsTrait::initialize($config);
    }
}

Database Table:, (*4)

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Table: Category         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ id          โ”‚ ingeter   โ”‚
โ”‚ name        โ”‚ string    โ”‚
โ”‚ createdAt*  โ”‚ timestamp โ”‚
โ”‚ updatedAt*  โ”‚ timestamp โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
* Required fields

Interface

echo $user->createdAt; // 2014-01-01 00:00:00
echo $user->updatedAt; // 2014-01-01 00:00:00

echo $user->getCreatedAt(); // DateTime object
$user->setCreatedAt(new DateTime());

echo $user->getUpdatedAt(); // DateTime object
$user->setUpdatedAt(new DateTime());

Testing

You can set the "current date" that the the trait uses with the "TimestampsTrait::setCurrentDate($date)" method., (*5)

TimestampsTrait::setCurrentDate('2014-03-01 10:00:00');

$user = new User();

echo $user->createdAt; // 2014-03-01 10:00:00
echo $user->updatedAt; // 2014-03-01 10:00:00

License

Copyright (c) 2014, Clippings Ltd. Developed by Ivan Kerin, (*6)

Under BSD-3-Clause license, read LICENSE file., (*7)

The Versions

11/07 2014

dev-master

9999999-dev

Automatic createdAt and updatedAt properties

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

11/07 2014

0.3.0

0.3.0.0

Automatic createdAt and updatedAt properties

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

08/07 2014

0.2.0

0.2.0.0

Automatic createdAt and updatedAt properties

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

26/06 2014

0.1.0

0.1.0.0

Automatic createdAt and updatedAt properties

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires