Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| HasGeneralDoctrineFields | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| onPrePersist | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| onPreUpdate | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\DoctrineEntityConverter\Concerns; |
| 3 | |
| 4 | use Apie\Core\ApieLib; |
| 5 | use Doctrine\ORM\Mapping\Column; |
| 6 | use Doctrine\ORM\Mapping\PrePersist; |
| 7 | use Doctrine\ORM\Mapping\PreUpdate; |
| 8 | |
| 9 | trait HasGeneralDoctrineFields |
| 10 | { |
| 11 | #[Column(name: 'created_in_internal_apie_version', type: 'string', length: 20, options: ['default' => 'unknown'])] |
| 12 | public string $internalApieVersion = ApieLib::VERSION; |
| 13 | |
| 14 | #[Column(name: 'updated_in_internal_apie_version', type: 'string', length: 20, options: ['default' => 'unknown'])] |
| 15 | public string $lastUpdateApieVersion = ApieLib::VERSION; |
| 16 | |
| 17 | #[Column(name: 'created_at', type: 'decimal', precision: 21, scale: 3)] |
| 18 | public string $createdAt; |
| 19 | |
| 20 | #[Column(name: 'updated_at', type: 'decimal', precision: 21, scale: 3)] |
| 21 | public string $updatedAt; |
| 22 | |
| 23 | #[PrePersist] |
| 24 | public function onPrePersist(): void |
| 25 | { |
| 26 | // time is stored as decimal because not all datetime formats support microseconds on db platforms. |
| 27 | $this->createdAt = ApieLib::getPsrClock()->now()->format('U.v'); |
| 28 | $this->updatedAt = $this->createdAt; |
| 29 | } |
| 30 | |
| 31 | #[PreUpdate] |
| 32 | public function onPreUpdate(): void |
| 33 | { |
| 34 | // time is stored as decimal because not all datetime formats support microseconds on db platforms. |
| 35 | $this->updatedAt = ApieLib::getPsrClock()->now()->format('U.v'); |
| 36 | $this->lastUpdateApieVersion = ApieLib::VERSION; |
| 37 | } |
| 38 | } |