7a1d3db94a8096a3ca3822367e480ec958dfa2a2
[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      * Constructs a metadata for the given attribute.
41      *
42      * @param string $name
43      */
44     public function __construct($name)
45     {
46         $this->name = $name;
47     }
48
49     /**
50      * {@inheritdoc}
51      */
52     public function getName()
53     {
54         return $this->name;
55     }
56
57     /**
58      * {@inheritdoc}
59      */
60     public function addGroup($group)
61     {
62         if (!in_array($group, $this->groups)) {
63             $this->groups[] = $group;
64         }
65     }
66
67     /**
68      * {@inheritdoc}
69      */
70     public function getGroups()
71     {
72         return $this->groups;
73     }
74
75     /**
76      * {@inheritdoc}
77      */
78     public function merge(AttributeMetadataInterface $attributeMetadata)
79     {
80         foreach ($attributeMetadata->getGroups() as $group) {
81             $this->addGroup($group);
82         }
83     }
84
85     /**
86      * Returns the names of the properties that should be serialized.
87      *
88      * @return string[]
89      */
90     public function __sleep()
91     {
92         return array('name', 'groups');
93     }
94 }