Timestamps
Automatic createdAt and updatedAt properties
Usage
Add the triats to the Repo and Model classes:
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:
┌─────────────────────────┐
│ 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.
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:00License
Copyright (c) 2014, Clippings Ltd. Developed by Ivan Kerin
Under BSD-3-Clause license, read LICENSE file.



