aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Helper
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2017-07-06 09:00:37 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2017-07-06 09:01:51 +0200
commit927c9e796ff6fad2bf82a965234f52932cdee657 (patch)
treed53d021f2f2c301646d40113330fdd6692cb08c5 /src/Wallabag/CoreBundle/Helper
parentb5d7eb148c4cd62ff187b08765f0c13c7d330fcf (diff)
downloadwallabag-927c9e796ff6fad2bf82a965234f52932cdee657.tar.gz
wallabag-927c9e796ff6fad2bf82a965234f52932cdee657.tar.zst
wallabag-927c9e796ff6fad2bf82a965234f52932cdee657.zip
Add EntityTimestampsTrait to handle dates
Refactorize timestamps() method to avoid re-writing it on each entity
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper')
-rw-r--r--src/Wallabag/CoreBundle/Helper/EntityTimestampsTrait.php24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/EntityTimestampsTrait.php b/src/Wallabag/CoreBundle/Helper/EntityTimestampsTrait.php
new file mode 100644
index 00000000..1b1ff54a
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Helper/EntityTimestampsTrait.php
@@ -0,0 +1,24 @@
1<?php
2
3namespace Wallabag\CoreBundle\Helper;
4
5use Doctrine\ORM\Mapping as ORM;
6
7/**
8 * Trait to handle created & updated date of an Entity.
9 */
10trait EntityTimestampsTrait
11{
12 /**
13 * @ORM\PrePersist
14 * @ORM\PreUpdate
15 */
16 public function timestamps()
17 {
18 if (null === $this->createdAt) {
19 $this->createdAt = new \DateTime();
20 }
21
22 $this->updatedAt = new \DateTime();
23 }
24}