Skip to content

Instantly share code, notes, and snippets.

@harmstyler
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harmstyler/8875484 to your computer and use it in GitHub Desktop.
Save harmstyler/8875484 to your computer and use it in GitHub Desktop.
<?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