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