Created
May 12, 2020 00:46
-
-
Save Dinour/c0e04cf3bb10e62499fc20b03f7bde11 to your computer and use it in GitHub Desktop.
Revisions
-
Daniele Rostellato revised this gist
Jul 17, 2017 . 2 changed files with 28 additions and 30 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -39,21 +39,25 @@ class EntityBase implements EntityBaseInterface * @ORM\PrePersist * @ORM\PreUpdate */ public function updatedTimestamps(): void { $dateTimeNow = new DateTime('now'); $this->setUpdatedAt($dateTimeNow); if ($this->getCreatedAt() === null) { $this->setCreatedAt($dateTimeNow); } } public function getCreatedAt() :?DateTime { return $this->createdAt; } public function setCreatedAt(DateTime $createdAt): self { $this->createdAt = $createdAt; return $this; } @@ -62,16 +66,11 @@ public function getUpdatedAt() :?DateTime { return $this->updatedAt; } public function setUpdatedAt(DateTime $updatedAt): self { $this->updatedAt = $updatedAt; return $this; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,37 +16,36 @@ interface EntityBaseInterface * @ORM\PrePersist * @ORM\PreUpdate */ public function updatedTimestamps(): void; /** * Get createdAt * * @return null|DateTime */ public function getCreatedAt(): ?DateTime /** * Set createdAt * * @param DateTime $createdAt * @return self */ public function setCreatedAt(DateTime $createdAt): self /** * Get updatedAt * * @param DateTime $createdAt * @return self */ public function getUpdatedAt(): ?DateTime /** * Set updatedAt * * @param DateTime $updatedAt * @return self */ public function setUpdatedAt(DateTime $updatedAt): self } -
Daniele Rostellato created this gist
Apr 5, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,77 @@ <?php namespace AppBundle\Mapping; use Doctrine\ORM\Mapping as ORM; use DateTime; /** * Class EntityBase * * PHP version 7.1 * * LICENSE: MIT * * @package AppBundle\Mapping * @author Lelle - Daniele Rostellato <[email protected]> * @license MIT * @version 1.0.0 * @since File available since Release 1.0.0 * @ORM\HasLifecycleCallbacks */ class EntityBase implements EntityBaseInterface { /** * @var DateTime $created * * @ORM\Column(name="created_at", type="datetime", nullable=false) */ protected $createdAt; /** * @var DateTime $updated * * @ORM\Column(name="updated_at", type="datetime", nullable=false) */ protected $updatedAt; /** * @ORM\PrePersist * @ORM\PreUpdate */ public function updatedTimestamps() :void { $dateTimeNow = new DateTime('now'); $this->setUpdatedAt($dateTimeNow); if ($this->getCreatedAt() === null) { $this->setCreatedAt($dateTimeNow); } } public function setUpdatedAt(DateTime $updatedAt) { $this->updatedAt = $updatedAt; return $this; } public function getUpdatedAt() :?DateTime { return $this->updatedAt; } public function setCreatedAt(DateTime $createdAt) { $this->createdAt = $createdAt; return $this; } public function getCreatedAt() :?DateTime { return $this->createdAt; } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ <?php namespace AppBundle\Mapping; use Doctrine\ORM\Mapping as ORM; use DateTime; /** * EntityBase Interface * * @author Lelle - Daniele Rostellato <[email protected]> */ interface EntityBaseInterface { /** * @ORM\PrePersist * @ORM\PreUpdate */ public function updatedTimestamps() :void; /** * Set updatedAt * * @param DateTime $updatedAt * * @return $this */ public function setUpdatedAt(DateTime $updatedAt); /** * Get updatedAt * * @return DateTime */ public function getUpdatedAt() :?DateTime; /** * Set createdAt * * @param DateTime $createdAt * * @return $this */ public function setCreatedAt(DateTime $createdAt); /** * Get createdAt * * @return DateTime */ public function getCreatedAt() :?DateTime; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ <?php namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; use AppBundle\Mapping\EntityBase; /** * MyEntity * * @ORM\HasLifecycleCallbacks */ class MyEntity extends EntityBase { // ... }