Debian Codegraph @

lib/3rdParty/composer/symfony/serializer/Attribute/Groups.php

raw symbols SCIP
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Serializer\Attribute;
13
14 use Symfony\Component\Serializer\Exception\InvalidArgumentException;
15
16 /**
17 * @author Kévin Dunglas <[email protected]>
18 */
19 #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY | \Attribute::TARGET_CLASS)]
20 class Groups
21 {
22 /**
23 * @var string[]
24 */
25 public readonly array $groups;
26
27 /**
28 * @param string|string[] $groups The groups to define on the attribute target
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 * @return string[]
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 }