| 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_METHOD | \Attribute::TARGET_PROPERTY | \Attribute::TARGET_CLASS)] |
| 20 |
class Groups |
| 21 |
{ |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
public readonly array $groups; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
public function __construct(string|array $groups) |
| 31 |
{ |
| 32 |
$this->groups = (array) $groups; |
| 33 |
|
| 34 |
if (!$this->groups) { |
| 35 |
throw new InvalidArgumentException(\sprintf('Parameter given to "%s" cannot be empty.', static::class)); |
| 36 |
} |
| 37 |
|
| 38 |
foreach ($this->groups as $group) { |
| 39 |
if (!\is_string($group) || '' === $group) { |
| 40 |
throw new InvalidArgumentException(\sprintf('Parameter given to "%s" must be a string or an array of non-empty strings.', static::class)); |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
#[\Deprecated('Use the "groups" property instead', 'symfony/serializer:7.4')] |
| 49 |
public function getGroups(): array |
| 50 |
{ |
| 51 |
return $this->groups; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
if (!class_exists(\Symfony\Component\Serializer\Annotation\Groups::class, false)) { |
| 56 |
class_alias(Groups::class, \Symfony\Component\Serializer\Annotation\Groups::class); |
| 57 |
} |