summaryrefslogtreecommitdiff
path: root/vendor/doctrine/orm/src/Mapping/DiscriminatorColumnMapping.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/doctrine/orm/src/Mapping/DiscriminatorColumnMapping.php')
-rw-r--r--vendor/doctrine/orm/src/Mapping/DiscriminatorColumnMapping.php83
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
3declare(strict_types=1);
4
5namespace Doctrine\ORM\Mapping;
6
7use ArrayAccess;
8use BackedEnum;
9use Exception;
10
11use function in_array;
12use function property_exists;
13
14/** @template-implements ArrayAccess<string, mixed> */
15final 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}