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