Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / serializer / Mapping / AttributeMetadata.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\Mapping;
13
14 /**
15  * {@inheritdoc}
16  *
17  * @author Kévin Dunglas <dunglas@gmail.com>
18  */
19 class AttributeMetadata implements AttributeMetadataInterface
20 {
21     /**
22      * @var string
23      *
24      * @internal This property is public in order to reduce the size of the
25      *           class' serialized representation. Do not access it. Use
26      *           {@link getName()} instead.
27      */
28     public $name;
29
30     /**
31      * @var array
32      *
33      * @internal This property is public in order to reduce the size of the
34      *           class' serialized representation. Do not access it. Use
35      *           {@link getGroups()} instead.
36      */
37     public $groups = array();
38
39     /**
40      * @var int|null
41      *
42      * @internal This property is public in order to reduce the size of the
43      *           class' serialized representation. Do not access it. Use
44      *           {@link getMaxDepth()} instead.
45      */
46     public $maxDepth;
47
48     /**
49      * Constructs a metadata for the given attribute.
50      *
51      * @param string $name
52      */
53     public function __construct($name)
54     {
55         $this->name = $name;
56     }
57
58     /**
59      * {@inheritdoc}
60      */
61     public function getName()
62     {
63         return $this->name;
64     }
65
66     /**
67      * {@inheritdoc}
68      */
69     public function addGroup($group)
70     {
71         if (!in_array($group, $this->groups)) {
72             $this->groups[] = $group;
73         }
74     }
75
76     /**
77      * {@inheritdoc}
78      */
79     public function getGroups()
80     {
81         return $this->groups;
82     }
83
84     /**
85      * {@inheritdoc}
86      */
87     public function setMaxDepth($maxDepth)
88     {
89         $this->maxDepth = $maxDepth;
90     }
91
92     /**
93      * {@inheritdoc}
94      */
95     public function getMaxDepth()
96     {
97         return $this->maxDepth;
98     }
99
100     /**
101      * {@inheritdoc}
102      */
103     public function merge(AttributeMetadataInterface $attributeMetadata)
104     {
105         foreach ($attributeMetadata->getGroups() as $group) {
106             $this->addGroup($group);
107         }
108
109         // Overwrite only if not defined
110         if (null === $this->maxDepth) {
111             $this->maxDepth = $attributeMetadata->getMaxDepth();
112         }
113     }
114
115     /**
116      * Returns the names of the properties that should be serialized.
117      *
118      * @return string[]
119      */
120     public function __sleep()
121     {
122         return array('name', 'groups', 'maxDepth');
123     }
124 }