| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\Serializer\Attribute; |
| 13 |
|
| 14 |
use Symfony\Component\Serializer\Exception\InvalidArgumentException; |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#[\Attribute(\Attribute::TARGET_CLASS)] |
| 20 |
class DiscriminatorMap |
| 21 |
{ |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
public function __construct( |
| 30 |
public readonly string $typeProperty, |
| 31 |
public readonly array $mapping, |
| 32 |
public readonly ?string $defaultType = null, |
| 33 |
) { |
| 34 |
if (!$typeProperty) { |
| 35 |
throw new InvalidArgumentException(\sprintf('Parameter "typeProperty" given to "%s" cannot be empty.', static::class)); |
| 36 |
} |
| 37 |
|
| 38 |
if (!$mapping) { |
| 39 |
throw new InvalidArgumentException(\sprintf('Parameter "mapping" given to "%s" cannot be empty.', static::class)); |
| 40 |
} |
| 41 |
|
| 42 |
if (null !== $this->defaultType && !\array_key_exists($this->defaultType, $this->mapping)) { |
| 43 |
throw new InvalidArgumentException(\sprintf('Default type "%s" given to "%s" must be present in "mapping" types.', $this->defaultType, static::class)); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
#[\Deprecated('Use the "typeProperty" property instead', 'symfony/serializer:7.4')] |
| 48 |
public function getTypeProperty(): string |
| 49 |
{ |
| 50 |
return $this->typeProperty; |
| 51 |
} |
| 52 |
|
| 53 |
#[\Deprecated('Use the "mapping" property instead', 'symfony/serializer:7.4')] |
| 54 |
public function getMapping(): array |
| 55 |
{ |
| 56 |
return $this->mapping; |
| 57 |
} |
| 58 |
|
| 59 |
#[\Deprecated('Use the "defaultType" property instead', 'symfony/serializer:7.4')] |
| 60 |
public function getDefaultType(): ?string |
| 61 |
{ |
| 62 |
return $this->defaultType; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
if (!class_exists(\Symfony\Component\Serializer\Annotation\DiscriminatorMap::class, false)) { |
| 67 |
class_alias(DiscriminatorMap::class, \Symfony\Component\Serializer\Annotation\DiscriminatorMap::class); |
| 68 |
} |