Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0e96e86

Browse files
committed
Added support for XML
1 parent d28a7e2 commit 0e96e86

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

src/Symfony/Component/Serializer/Mapping/Loader/XmlFileLoader.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,47 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata)
6363
$attributeMetadata->addGroup((string) $group);
6464
}
6565

66+
foreach ($attribute->methods as $methods) {
67+
if (isset($methods['accessor'])) {
68+
$attributeMetadata->setMethodsAccessor((string) $methods['accessor']);
69+
}
70+
71+
if (isset($methods['mutator'])) {
72+
$attributeMetadata->setMethodsMutator((string) $methods['mutator']);
73+
}
74+
}
75+
76+
if (isset($attribute['exclude'])) {
77+
$attributeMetadata->setExclude((bool) $attribute['exclude']);
78+
}
79+
80+
if (isset($attribute['expose'])) {
81+
$attributeMetadata->setExpose((bool) $attribute['expose']);
82+
}
83+
6684
if (isset($attribute['max-depth'])) {
6785
$attributeMetadata->setMaxDepth((int) $attribute['max-depth']);
6886
}
87+
88+
if (isset($attribute['read-only'])) {
89+
$attributeMetadata->setReadOnly((bool) $attribute['read-only']);
90+
}
91+
92+
if (isset($attribute['serialized-name'])) {
93+
$attributeMetadata->setSerializedName((string) $attribute['serialized-name']);
94+
}
95+
96+
if (isset($attribute['type'])) {
97+
$attributeMetadata->setType((string) $attribute['type']);
98+
}
99+
}
100+
101+
if (isset($xml['exclusion-policy'])) {
102+
$classMetadata->setExclusionPolicy((string) $xml['exclusion-policy']);
103+
}
104+
105+
if (isset($xml['read-only'])) {
106+
$classMetadata->setReadOnly((bool) $xml['read-only']);
69107
}
70108

71109
if (isset($xml->{'discriminator-map'})) {

src/Symfony/Component/Serializer/Mapping/Loader/YamlFileLoader.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata)
156156

157157
$classMetadata->setExclusionPolicy($yaml['exclusion_policy']);
158158
}
159+
159160
if (isset($yaml['read_only'])) {
160161
if (!\is_bool($yaml['read_only'])) {
161162
throw new MappingException(sprintf('The "read_only" value must be a boolean in "%s" for the class "%s".', $this->file, $classMetadata->getName()));

src/Symfony/Component/Serializer/Normalizer/MetadataAwareNormalizer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ final class MetadataAwareNormalizer extends AbstractObjectNormalizer
3232
*/
3333
protected $propertyAccessor;
3434

35-
public function __construct(ClassMetadataFactoryInterface $classMetadataFactory = null, NameConverterInterface $nameConverter = null, PropertyTypeExtractorInterface $propertyTypeExtractor = null, ClassDiscriminatorResolverInterface $classDiscriminatorResolver = null, PropertyAccessorInterface $propertyAccessor = null) {
35+
public function __construct(ClassMetadataFactoryInterface $classMetadataFactory = null, NameConverterInterface $nameConverter = null, PropertyTypeExtractorInterface $propertyTypeExtractor = null, ClassDiscriminatorResolverInterface $classDiscriminatorResolver = null, PropertyAccessorInterface $propertyAccessor = null)
36+
{
3637
if (null === $propertyAccessor) {
3738
$propertyAccessor = PropertyAccess::createPropertyAccessor();
3839
}
3940
$this->propertyAccessor = $propertyAccessor;
4041
parent::__construct($classMetadataFactory, $nameConverter, $propertyTypeExtractor, $classDiscriminatorResolver);
4142
}
4243

43-
4444
/**
4545
* {@inheritdoc}
4646
*/
@@ -173,7 +173,6 @@ protected function updateData(array $data, string $attribute, $attributeValue/*
173173
}
174174
$object = func_get_arg(3);
175175

176-
177176
/** @var ClassMetadataInterface $classMetadata */
178177
$classMetadata = $this->classMetadataFactory->getMetadataFor($object);
179178
$attributeMetadata = $classMetadata->getAttributesMetadata();
@@ -198,10 +197,11 @@ protected function prepareForDenormalization($data/*, string $class*/)
198197
{
199198
if (1 === \func_num_args()) {
200199
@trigger_error('Second argument to MetadataAwareNormalizer must be the class name', E_USER_DEPRECATED);
200+
201201
return (array) $data;
202202
}
203203

204-
$class = func_get_arg(1);
204+
$class = func_get_arg(1);
205205
$preparedData = array();
206206
$data = (array) $data;
207207
/** @var ClassMetadataInterface $classMetadata */

0 commit comments

Comments
 (0)