murph-doc/docs/utils/doctrine.md

36 lines
900 B
Markdown
Raw Permalink Normal View History

2022-05-07 13:47:17 +02:00
# Doctrine
2022-05-07 16:18:25 +02:00
## 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
2023-02-09 21:50:06 +01:00
```php-inline title="src/Entity/FooEntity.php"
namespace App/Entity;
2022-05-07 16:18:25 +02:00
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;
2023-02-09 21:50:06 +01:00
#[ORM\Entity(repositoryClass: FooRepository::class)]
#[ORM\HasLifecycleCallbacks]
2022-05-07 16:18:25 +02:00
class FooEntity implements EntityInterface
{
use Timestampable;
// ...
}
```