-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding Timestampable entity behavior
- Loading branch information
afrezet
committed
Mar 15, 2015
1 parent
fbd2241
commit 45825c1
Showing
2 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
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
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
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; | ||
} | ||
} |