murph-doc/docs/utils/doctrine.md
Simon Vieille 385af624a6
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
update theme
2023-02-09 21:50:06 +01:00

36 lines
900 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
```php-inline title="src/Entity/FooEntity.php"
namespace App/Entity;
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;
// ...
}
```