| 1 | <?php |
||
| 25 | class ClassMetadata extends GenericMetadata implements ClassMetadataInterface |
||
| 26 | { |
||
| 27 | const INVALID_DISCRIMINATOR_VALUE = '19cf8396-0fe1-487f-bd32-d5d34e2b4f68'; |
||
| 28 | |||
| 29 | /*** |
||
| 30 | * @var PropertyMetadataInterface|null |
||
| 31 | * @internal |
||
| 32 | */ |
||
| 33 | public $discField; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var array |
||
| 37 | * @internal |
||
| 38 | */ |
||
| 39 | public $discMap; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var string |
||
| 43 | * @internal |
||
| 44 | */ |
||
| 45 | public $discError; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @inheritdoc |
||
| 49 | */ |
||
| 50 | 10 | public function getDiscriminatorField() |
|
| 54 | |||
| 55 | /** |
||
| 56 | * Sets discriminator field |
||
| 57 | * |
||
| 58 | * @param PropertyMetadataInterface|null $field |
||
| 59 | * @return $this |
||
| 60 | */ |
||
| 61 | 11 | public function setDiscriminatorField(PropertyMetadataInterface $field = null) |
|
| 67 | |||
| 68 | /** |
||
| 69 | * Sets discriminator map |
||
| 70 | * |
||
| 71 | * @param array $map |
||
| 72 | * @return $this |
||
| 73 | */ |
||
| 74 | 12 | public function setDiscriminatorMap(array $map) |
|
| 80 | |||
| 81 | /** |
||
| 82 | * @return string |
||
| 83 | */ |
||
| 84 | public function getDiscriminatorError() |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @param string $error |
||
| 91 | * @return $this |
||
| 92 | */ |
||
| 93 | 11 | public function setDiscriminatorError($error) |
|
| 99 | |||
| 100 | /** |
||
| 101 | * @inheritdoc |
||
| 102 | */ |
||
| 103 | 8 | public function getDiscriminatorClass($value) |
|
| 104 | { |
||
| 105 | 8 | if (!array_key_exists($value, $this->discMap)) { |
|
| 106 | 1 | $error = new Error( |
|
| 107 | 1 | rand(), |
|
| 108 | 1 | null, |
|
| 109 | 1 | 422, |
|
| 110 | 1 | self::INVALID_DISCRIMINATOR_VALUE, |
|
| 111 | 1 | str_replace('{{value}}', (string) $value, $this->discError) |
|
| 112 | 1 | ); |
|
| 113 | |||
| 114 | 1 | throw new JsonApiException($error, 422); |
|
| 115 | } |
||
| 116 | |||
| 117 | 8 | return $this->discMap[$value]; |
|
| 118 | } |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @inheritdoc |
||
| 122 | */ |
||
| 123 | 1 | public function mergeMetadata($metadata) |
|
| 127 | } |
||
| 128 |