Skip to content

Commit

Permalink
adding Timestampable entity behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
afrezet committed Mar 15, 2015
1 parent fbd2241 commit 45825c1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Behavior/ControllerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ trait ControllerTrait
* @param Exception $previous
* @return NotFoundHttpException
*/
public abstract function createNotFoundException($message = 'Not Found', Exception $previous = NULL);
public abstract function createNotFoundException($message = 'Not Found', Exception $previous = null);

/**
* Abstract generate url method. Should return a url string
Expand Down
57 changes: 57 additions & 0 deletions Entity/Behaviors/Timestampable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace BlueBear\BaseBundle\Entity\Behavior;

use DateTime;

trait Timestampable
{
/**
* @var DateTime
* @ORM\Column(name="created_at", type="datetime")
*/
protected $createdAt;

/**
* @var DateTime
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
*/
protected $updatedAt;

/**
* @ORM\PrePersist()
* @return $this
*/
public function setCreatedAt()
{
$this->createdAt = new DateTime();
return $this;
}

/**
* @return DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}

/**
* @ORM\PrePersist()
* @ORM\PreUpdate()
* @return $this
*/
public function setUpdatedAt()
{
$this->updatedAt = new DateTime();
return $this;
}

/**
* @return DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
}

0 comments on commit 45825c1

Please sign in to comment.