1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Cycle\ORM\Entity\Behavior\Schema; |
||
6 | |||
7 | use Cycle\ORM\Entity\Behavior\Dispatcher\ListenerProvider; |
||
8 | use Cycle\ORM\SchemaInterface; |
||
9 | use Cycle\Schema\Registry; |
||
10 | use Cycle\Schema\SchemaModifierInterface; |
||
11 | |||
12 | abstract class BaseModifier implements SchemaModifierInterface |
||
13 | { |
||
14 | protected string $role; |
||
15 | |||
16 | public function compute(Registry $registry): void {} |
||
17 | |||
18 | public function render(Registry $registry): void {} |
||
19 | |||
20 | final public function withRole(string $role): static |
||
21 | { |
||
22 | $clone = clone $this; |
||
23 | $clone->role = $role; |
||
24 | return $clone; |
||
25 | } |
||
26 | |||
27 | final public function modifySchema(array &$schema): void |
||
28 | { |
||
29 | // todo: compare with default constructor values |
||
30 | $args = $this->getListenerArgs(); |
||
31 | if ($args === []) { |
||
32 | $schema[SchemaInterface::LISTENERS][] = $this->getListenerClass(); |
||
33 | return; |
||
34 | 112 | } |
|
35 | $schema[SchemaInterface::LISTENERS][] = [ |
||
36 | 112 | ListenerProvider::DEFINITION_CLASS => $this->getListenerClass(), |
|
37 | 112 | ListenerProvider::DEFINITION_ARGS => $args, |
|
38 | 112 | ]; |
|
39 | } |
||
40 | |||
41 | 96 | /** |
|
42 | * @return class-string |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
43 | */ |
||
44 | 96 | abstract protected function getListenerClass(): string; |
|
45 | 96 | ||
46 | /** |
||
47 | * @return array<string, mixed> |
||
48 | */ |
||
49 | 96 | abstract protected function getListenerArgs(): array; |
|
50 | } |
||
51 |