7a9b0bd2c1052d6d35b658fc716411b5d8d0fd02
[yaffs-website] / vendor / symfony / serializer / Annotation / Groups.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
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\Annotation;
13
14 use Symfony\Component\Serializer\Exception\InvalidArgumentException;
15
16 /**
17  * Annotation class for @Groups().
18  *
19  * @Annotation
20  * @Target({"PROPERTY", "METHOD"})
21  *
22  * @author Kévin Dunglas <dunglas@gmail.com>
23  */
24 class Groups
25 {
26     /**
27      * @var string[]
28      */
29     private $groups;
30
31     /**
32      * @throws InvalidArgumentException
33      */
34     public function __construct(array $data)
35     {
36         if (!isset($data['value']) || !$data['value']) {
37             throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" cannot be empty.', \get_class($this)));
38         }
39
40         $value = (array) $data['value'];
41         foreach ($value as $group) {
42             if (!\is_string($group)) {
43                 throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a string or an array of strings.', \get_class($this)));
44             }
45         }
46
47         $this->groups = $value;
48     }
49
50     /**
51      * Gets groups.
52      *
53      * @return string[]
54      */
55     public function getGroups()
56     {
57         return $this->groups;
58     }
59 }