Advertisement
Guest User

CommonEntity

a guest
Jul 21st, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.83 KB | None | 0 0
  1. /**
  2.  * File CommonEntity
  3.  * Entity ancestor
  4.  *
  5.  * - Identified
  6.  * - Timestamped
  7.  *
  8.  * @ORM\MappedSuperclass
  9.  * @ORM\HasLifecycleCallbacks
  10.  *
  11.  * Petr Blažíček 2014
  12.  */
  13. abstract class CommonEntity extends SimpleEntity
  14. {
  15.     /**
  16.      * @ORM\Column(type="datetimetz")
  17.      * @var DateTime
  18.      */
  19.     protected $created;
  20.  
  21.     /**
  22.      * @ORM\Column(type="datetimetz")
  23.      * @var DateTime
  24.      */
  25.     protected $updated;
  26.  
  27.     /**
  28.      * @return DateTime
  29.      */
  30.     public function getCreated()
  31.     {
  32.         return $this->created;
  33.     }
  34.  
  35.     /**
  36.      * @ORM\PrePersist
  37.      */
  38.     public function prePersist()
  39.     {
  40.         $this->updated = $this->created = new DateTime();
  41.     }
  42.  
  43.     /**
  44.      * @return DateTime
  45.      */
  46.     public function getUpdated()
  47.     {
  48.         return $this->updated;
  49.     }
  50.  
  51.     /**
  52.      * @ORM\PreUpdate
  53.      */
  54.     public function preUpdate()
  55.     {
  56.         $this->updated = new DateTime();
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement