mof/timestampable
Composer 安装命令:
composer require mof/timestampable
包简介
Generates automatically creation and update's date of Doctrine entity property
README 文档
README
Presentation
This little library for Doctrine projects allows you to automatically handle creation and update on certain properties of your entity.
How install
You need to install it via composer :
composer require mof/timestampable
Then you need to register the annotations and add the event subscriber to the Doctrine event manager :
AnnotationRegistry::registerLoader('class_exists'); //This register the annotation
$annotationReader = new AnnotationReader();
$eventManager->addEventSubscriber(new TimestampableSubscriber($annotationReader));
You can give to the TimestampableSubcriber constructor any class that implements the Doctrine\Common\Annotations\Reader interface.
Then you ready to go.
Usage
In your entity, you can add the events the property will listen to, there are 2 events available :
/**
* When an entity is created
* @var \DateTime
* @ORM\Column(type="datetime", name="created_at")
* @Timestampable(on=Timestampable::ON_CREATE)
*/
protected $createdAt;
/**
* When an entity is updated (the date is also set when an entity is created)
* @var \DateTime
* @ORM\Column(type="datetime", name="updated_at")
* @Timestampable(on=Timestampable::ON_UPDATE)
*/
protected $updatedAt;
Tests
You can run the tests by cloning the project and then type :
composer install
vendor/bin/codecept run
The tests use sqlite for the database behind the scene, for more information, see https://www.php.net/manual/fr/sqlite.installation.php.
统计信息
- 总下载量: 22
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-03-17