1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Cycle\ORM\Entity\Behavior\Uuid\Listener; |
||
6 | |||
7 | use Cycle\ORM\Entity\Behavior\Attribute\Listen; |
||
8 | use Cycle\ORM\Entity\Behavior\Event\Mapper\Command\OnCreate; |
||
9 | use Ramsey\Uuid\Type\Hexadecimal; |
||
10 | use Ramsey\Uuid\Uuid; |
||
11 | |||
12 | final class Uuid6 |
||
13 | { |
||
14 | 8 | public function __construct( |
|
15 | private string $field = 'uuid', |
||
16 | private Hexadecimal|string|null $node = null, |
||
17 | private ?int $clockSeq = null, |
||
18 | private bool $nullable = false |
||
19 | 8 | ) { |
|
20 | } |
||
21 | 8 | ||
22 | #[Listen(OnCreate::class)] |
||
23 | public function __invoke(OnCreate $event): void |
||
24 | 8 | { |
|
25 | if ($this->nullable || isset($event->state->getData()[$this->field])) { |
||
26 | return; |
||
27 | } |
||
28 | 8 | ||
29 | 8 | if (\is_string($this->node)) { |
|
30 | $this->node = new Hexadecimal($this->node); |
||
31 | 8 | } |
|
32 | |||
33 | $event->state->register($this->field, Uuid::uuid6($this->node, $this->clockSeq)); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
34 | } |
||
35 | } |
||
36 |