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