Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/serializer/Mapping/ClassMetadata.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 1fec387a4317 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
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 ClassMetadata implements ClassMetadataInterface | |
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 AttributeMetadataInterface[] | |
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 getAttributesMetadata()} instead. | |
36 */ | |
37 public $attributesMetadata = array(); | |
38 | |
39 /** | |
40 * @var \ReflectionClass | |
41 */ | |
42 private $reflClass; | |
43 | |
44 /** | |
45 * Constructs a metadata for the given class. | |
46 * | |
47 * @param string $class | |
48 */ | |
49 public function __construct($class) | |
50 { | |
51 $this->name = $class; | |
52 } | |
53 | |
54 /** | |
55 * {@inheritdoc} | |
56 */ | |
57 public function getName() | |
58 { | |
59 return $this->name; | |
60 } | |
61 | |
62 /** | |
63 * {@inheritdoc} | |
64 */ | |
65 public function addAttributeMetadata(AttributeMetadataInterface $attributeMetadata) | |
66 { | |
67 $this->attributesMetadata[$attributeMetadata->getName()] = $attributeMetadata; | |
68 } | |
69 | |
70 /** | |
71 * {@inheritdoc} | |
72 */ | |
73 public function getAttributesMetadata() | |
74 { | |
75 return $this->attributesMetadata; | |
76 } | |
77 | |
78 /** | |
79 * {@inheritdoc} | |
80 */ | |
81 public function merge(ClassMetadataInterface $classMetadata) | |
82 { | |
83 foreach ($classMetadata->getAttributesMetadata() as $attributeMetadata) { | |
84 if (isset($this->attributesMetadata[$attributeMetadata->getName()])) { | |
85 $this->attributesMetadata[$attributeMetadata->getName()]->merge($attributeMetadata); | |
86 } else { | |
87 $this->addAttributeMetadata($attributeMetadata); | |
88 } | |
89 } | |
90 } | |
91 | |
92 /** | |
93 * {@inheritdoc} | |
94 */ | |
95 public function getReflectionClass() | |
96 { | |
97 if (!$this->reflClass) { | |
98 $this->reflClass = new \ReflectionClass($this->getName()); | |
99 } | |
100 | |
101 return $this->reflClass; | |
102 } | |
103 | |
104 /** | |
105 * Returns the names of the properties that should be serialized. | |
106 * | |
107 * @return string[] | |
108 */ | |
109 public function __sleep() | |
110 { | |
111 return array( | |
112 'name', | |
113 'attributesMetadata', | |
114 ); | |
115 } | |
116 } |