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/DiscriminatorColumnMapping.php | |
parent | 94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff) | |
download | AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip |
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/doctrine/orm/src/Mapping/DiscriminatorColumnMapping.php')
-rw-r--r-- | vendor/doctrine/orm/src/Mapping/DiscriminatorColumnMapping.php | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/vendor/doctrine/orm/src/Mapping/DiscriminatorColumnMapping.php b/vendor/doctrine/orm/src/Mapping/DiscriminatorColumnMapping.php new file mode 100644 index 0000000..4ccb71c --- /dev/null +++ b/vendor/doctrine/orm/src/Mapping/DiscriminatorColumnMapping.php | |||
@@ -0,0 +1,83 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\ORM\Mapping; | ||
6 | |||
7 | use ArrayAccess; | ||
8 | use BackedEnum; | ||
9 | use Exception; | ||
10 | |||
11 | use function in_array; | ||
12 | use function property_exists; | ||
13 | |||
14 | /** @template-implements ArrayAccess<string, mixed> */ | ||
15 | final class DiscriminatorColumnMapping implements ArrayAccess | ||
16 | { | ||
17 | use ArrayAccessImplementation; | ||
18 | |||
19 | /** The database length of the column. Optional. Default value taken from the type. */ | ||
20 | public int|null $length = null; | ||
21 | |||
22 | public string|null $columnDefinition = null; | ||
23 | |||
24 | /** @var class-string<BackedEnum>|null */ | ||
25 | public string|null $enumType = null; | ||
26 | |||
27 | /** @var array<string, mixed> */ | ||
28 | public array $options = []; | ||
29 | |||
30 | public function __construct( | ||
31 | public string $type, | ||
32 | public string $fieldName, | ||
33 | public string $name, | ||
34 | ) { | ||
35 | } | ||
36 | |||
37 | /** | ||
38 | * @psalm-param array{ | ||
39 | * type: string, | ||
40 | * fieldName: string, | ||
41 | * name: string, | ||
42 | * length?: int|null, | ||
43 | * columnDefinition?: string|null, | ||
44 | * enumType?: class-string<BackedEnum>|null, | ||
45 | * options?: array<string, mixed>|null, | ||
46 | * } $mappingArray | ||
47 | */ | ||
48 | public static function fromMappingArray(array $mappingArray): self | ||
49 | { | ||
50 | $mapping = new self( | ||
51 | $mappingArray['type'], | ||
52 | $mappingArray['fieldName'], | ||
53 | $mappingArray['name'], | ||
54 | ); | ||
55 | foreach ($mappingArray as $key => $value) { | ||
56 | if (in_array($key, ['type', 'fieldName', 'name'])) { | ||
57 | continue; | ||
58 | } | ||
59 | |||
60 | if (property_exists($mapping, $key)) { | ||
61 | $mapping->$key = $value ?? $mapping->$key; | ||
62 | } else { | ||
63 | throw new Exception('Unknown property ' . $key . ' on class ' . static::class); | ||
64 | } | ||
65 | } | ||
66 | |||
67 | return $mapping; | ||
68 | } | ||
69 | |||
70 | /** @return list<string> */ | ||
71 | public function __sleep(): array | ||
72 | { | ||
73 | $serialized = ['type', 'fieldName', 'name']; | ||
74 | |||
75 | foreach (['length', 'columnDefinition', 'enumType', 'options'] as $stringOrArrayKey) { | ||
76 | if ($this->$stringOrArrayKey !== null) { | ||
77 | $serialized[] = $stringOrArrayKey; | ||
78 | } | ||
79 | } | ||
80 | |||
81 | return $serialized; | ||
82 | } | ||
83 | } | ||