murph-doc/docs/utils/doctrine.md
2022-05-07 16:18:25 +02:00

37 lines
869 B
Markdown

# Doctrine
## Timestampable
`App\Core\Doctrine\Timestampable` is a trait usuble in an entity. It adds `createdAt and updatedAt` datetime attributes with the setters and the getters :
* `setCreatedAt(?\DateTime $createdAt): self`
* `setUpdated(?\DateTime $createdAt): self`
* `getCreatedAt(): ?\DateTime`
* `getUpdatedAt(): ?\DateTime`
When the entity is created or updated, `createdAt` and `updatedAt` are automatically updated to.
### Usage
```
// App/Entity/FooEntity;
use use App\Core\Entity\EntityInterface;
use Doctrine\ORM\Mapping as ORM;
use App\Core\Doctrine\Timestampable;
use App\Core\Entity\EntityInterface;
use App\Repository\FooRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=FooRepository::class)
* @ORM\HasLifecycleCallbacks
*/
class FooEntity implements EntityInterface
{
use Timestampable;
// ...
}
```