Last active
August 29, 2015 13:56
-
-
Save harmstyler/8875484 to your computer and use it in GitHub Desktop.
This file contains 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 characters
<?php | |
/** | |
* TimeStampedEntity.php | |
*/ | |
namespace HarmsTyler\Common\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* TimeStampedEntity | |
* | |
* @ORM\MappedSuperclass | |
* @ORM\HasLifecycleCallbacks | |
*/ | |
abstract class TimeStampedEntity { | |
/** | |
* @var \DateTime | |
* | |
* @ORM\Column(name="created", type="datetime") | |
*/ | |
private $created; | |
/** | |
* @var \DateTime | |
* | |
* @ORM\Column(name="updated", type="datetime") | |
*/ | |
private $updated; | |
/** | |
* Set created | |
* | |
* @param \DateTime $created | |
* @return Post | |
*/ | |
public function setCreated($created) | |
{ | |
$this->created = $created; | |
return $this; | |
} | |
/** | |
* Get created | |
* | |
* @return \DateTime | |
*/ | |
public function getCreated() | |
{ | |
return $this->created; | |
} | |
/** | |
* Set updated | |
* | |
* @param \DateTime $updated | |
* @return Post | |
*/ | |
public function setUpdated($updated) | |
{ | |
$this->updated = $updated; | |
return $this; | |
} | |
/** | |
* Get updated | |
* | |
* @return \DateTime | |
*/ | |
public function getUpdated() | |
{ | |
return $this->updated; | |
} | |
/** | |
* Auto set the updated date | |
* | |
* @ORM\PreUpdate | |
*/ | |
public function setUpdatedValue() | |
{ | |
$this->setUpdated(new \DateTime()); | |
} | |
/** | |
* Set initial value for created/updated values | |
* | |
* @ORM\PrePersist | |
*/ | |
public function setCreatedValues() | |
{ | |
$this->setCreated(new \DateTime()); | |
$this->setUpdated(new \DateTime()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment