diff options
author | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
commit | bf6655a534a6775d30cafa67bd801276bda1d98d (patch) | |
tree | c6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/doctrine/orm/src/Mapping/JoinTableMapping.php | |
parent | 94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff) | |
download | AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip |
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/doctrine/orm/src/Mapping/JoinTableMapping.php')
-rw-r--r-- | vendor/doctrine/orm/src/Mapping/JoinTableMapping.php | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/vendor/doctrine/orm/src/Mapping/JoinTableMapping.php b/vendor/doctrine/orm/src/Mapping/JoinTableMapping.php new file mode 100644 index 0000000..c8b4968 --- /dev/null +++ b/vendor/doctrine/orm/src/Mapping/JoinTableMapping.php | |||
@@ -0,0 +1,115 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\ORM\Mapping; | ||
6 | |||
7 | use ArrayAccess; | ||
8 | |||
9 | use function array_map; | ||
10 | use function in_array; | ||
11 | |||
12 | /** @template-implements ArrayAccess<string, mixed> */ | ||
13 | final class JoinTableMapping implements ArrayAccess | ||
14 | { | ||
15 | use ArrayAccessImplementation; | ||
16 | |||
17 | public bool|null $quoted = null; | ||
18 | |||
19 | /** @var list<JoinColumnMapping> */ | ||
20 | public array $joinColumns = []; | ||
21 | |||
22 | /** @var list<JoinColumnMapping> */ | ||
23 | public array $inverseJoinColumns = []; | ||
24 | |||
25 | /** @var array<string, mixed> */ | ||
26 | public array $options = []; | ||
27 | |||
28 | public string|null $schema = null; | ||
29 | |||
30 | public function __construct(public string $name) | ||
31 | { | ||
32 | } | ||
33 | |||
34 | /** | ||
35 | * @param mixed[] $mappingArray | ||
36 | * @psalm-param array{ | ||
37 | * name: string, | ||
38 | * quoted?: bool|null, | ||
39 | * joinColumns?: mixed[], | ||
40 | * inverseJoinColumns?: mixed[], | ||
41 | * schema?: string|null, | ||
42 | * options?: array<string, mixed> | ||
43 | * } $mappingArray | ||
44 | */ | ||
45 | public static function fromMappingArray(array $mappingArray): self | ||
46 | { | ||
47 | $mapping = new self($mappingArray['name']); | ||
48 | |||
49 | foreach (['quoted', 'schema', 'options'] as $key) { | ||
50 | if (isset($mappingArray[$key])) { | ||
51 | $mapping->$key = $mappingArray[$key]; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | if (isset($mappingArray['joinColumns'])) { | ||
56 | foreach ($mappingArray['joinColumns'] as $column) { | ||
57 | $mapping->joinColumns[] = JoinColumnMapping::fromMappingArray($column); | ||
58 | } | ||
59 | } | ||
60 | |||
61 | if (isset($mappingArray['inverseJoinColumns'])) { | ||
62 | foreach ($mappingArray['inverseJoinColumns'] as $column) { | ||
63 | $mapping->inverseJoinColumns[] = JoinColumnMapping::fromMappingArray($column); | ||
64 | } | ||
65 | } | ||
66 | |||
67 | return $mapping; | ||
68 | } | ||
69 | |||
70 | public function offsetSet(mixed $offset, mixed $value): void | ||
71 | { | ||
72 | if (in_array($offset, ['joinColumns', 'inverseJoinColumns'], true)) { | ||
73 | $joinColumns = []; | ||
74 | foreach ($value as $column) { | ||
75 | $joinColumns[] = JoinColumnMapping::fromMappingArray($column); | ||
76 | } | ||
77 | |||
78 | $value = $joinColumns; | ||
79 | } | ||
80 | |||
81 | $this->$offset = $value; | ||
82 | } | ||
83 | |||
84 | /** @return mixed[] */ | ||
85 | public function toArray(): array | ||
86 | { | ||
87 | $array = (array) $this; | ||
88 | |||
89 | $toArray = static fn (JoinColumnMapping $column): array => (array) $column; | ||
90 | $array['joinColumns'] = array_map($toArray, $array['joinColumns']); | ||
91 | $array['inverseJoinColumns'] = array_map($toArray, $array['inverseJoinColumns']); | ||
92 | |||
93 | return $array; | ||
94 | } | ||
95 | |||
96 | /** @return list<string> */ | ||
97 | public function __sleep(): array | ||
98 | { | ||
99 | $serialized = []; | ||
100 | |||
101 | foreach (['joinColumns', 'inverseJoinColumns', 'name', 'schema', 'options'] as $stringOrArrayKey) { | ||
102 | if ($this->$stringOrArrayKey !== null) { | ||
103 | $serialized[] = $stringOrArrayKey; | ||
104 | } | ||
105 | } | ||
106 | |||
107 | foreach (['quoted'] as $boolKey) { | ||
108 | if ($this->$boolKey) { | ||
109 | $serialized[] = $boolKey; | ||
110 | } | ||
111 | } | ||
112 | |||
113 | return $serialized; | ||
114 | } | ||
115 | } | ||