Created
February 7, 2021 14:11
-
-
Save kaesetoast/be4efec9d9d61f5d99f0c7214abedd89 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 | |
namespace App\Entity; | |
use ApiPlatform\Core\Annotation\ApiProperty; | |
use Doctrine\ORM\Mapping as ORM; | |
use Ramsey\Uuid\Uuid; | |
trait UuidTrait | |
{ | |
/** | |
* @ORM\Column(type="uuid", unique=true) | |
* @ORM\Id | |
* @ApiProperty(identifier=true) | |
*/ | |
protected $id; | |
/** | |
* @ORM\Column(type="datetime") | |
*/ | |
protected $created_at; | |
public function __construct() | |
{ | |
$this->id = Uuid::uuid4(); | |
$this->setCreatedAt(new \DateTime()); | |
} | |
/** | |
* @return mixed | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/** | |
* @param mixed $id | |
* @return UuidTrait | |
*/ | |
public function setId($id) | |
{ | |
$this->id = $id; | |
return $this; | |
} | |
public function getCreatedAt(): ?\DateTimeInterface | |
{ | |
return $this->created_at; | |
} | |
public function setCreatedAt(\DateTimeInterface $created_at): self | |
{ | |
$this->created_at = $created_at; | |
return $this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment