| 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 | \Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] |
| 20 |
class Context |
| 21 |
{ |
| 22 |
public readonly array $groups; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public function __construct( |
| 33 |
public readonly array $context = [], |
| 34 |
public readonly array $normalizationContext = [], |
| 35 |
public readonly array $denormalizationContext = [], |
| 36 |
string|array $groups = [], |
| 37 |
) { |
| 38 |
if (!$context && !$normalizationContext && !$denormalizationContext) { |
| 39 |
throw new InvalidArgumentException(\sprintf('At least one of the "context", "normalizationContext", or "denormalizationContext" options must be provided as a non-empty array to "%s".', static::class)); |
| 40 |
} |
| 41 |
|
| 42 |
$this->groups = (array) $groups; |
| 43 |
|
| 44 |
foreach ($this->groups as $group) { |
| 45 |
if (!\is_string($group)) { |
| 46 |
throw new InvalidArgumentException(\sprintf('Parameter "groups" given to "%s" must be a string or an array of strings, "%s" given.', static::class, get_debug_type($group))); |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
#[\Deprecated('Use the "context" property instead', 'symfony/serializer:7.4')] |
| 52 |
public function getContext(): array |
| 53 |
{ |
| 54 |
return $this->context; |
| 55 |
} |
| 56 |
|
| 57 |
#[\Deprecated('Use the "normalizationContext" property instead', 'symfony/serializer:7.4')] |
| 58 |
public function getNormalizationContext(): array |
| 59 |
{ |
| 60 |
return $this->normalizationContext; |
| 61 |
} |
| 62 |
|
| 63 |
#[\Deprecated('Use the "denormalizationContext" property instead', 'symfony/serializer:7.4')] |
| 64 |
public function getDenormalizationContext(): array |
| 65 |
{ |
| 66 |
return $this->denormalizationContext; |
| 67 |
} |
| 68 |
|
| 69 |
#[\Deprecated('Use the "groups" property instead', 'symfony/serializer:7.4')] |
| 70 |
public function getGroups(): array |
| 71 |
{ |
| 72 |
return $this->groups; |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
if (!class_exists(\Symfony\Component\Serializer\Annotation\Context::class, false)) { |
| 77 |
class_alias(Context::class, \Symfony\Component\Serializer\Annotation\Context::class); |
| 78 |
} |