Skip to content

Commit a0a3853

Browse files
fix: XML/YAML cast values (#4800)
* fix: XML/YAML cast values * fix: review
1 parent 607142c commit a0a3853

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

src/Metadata/Extractor/ResourceExtractorTrait.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,16 @@ private function buildArgs(SimpleXMLElement $resource): ?array
9797
return $data;
9898
}
9999

100-
/**
101-
* @return string[]
102-
*/
103100
private function buildValues(SimpleXMLElement $resource): array
104101
{
105102
$data = [];
106103
foreach ($resource->value as $value) {
107104
if (null !== $value->attributes()->name) {
108-
$data[(string) $value->attributes()->name] = isset($value->values) ? $this->buildValues($value->values) : (string) $value;
105+
$data[(string) $value->attributes()->name] = isset($value->values) ? $this->buildValues($value->values) : XmlUtils::phpize($value->__toString());
109106
continue;
110107
}
111108

112-
$data[] = isset($value->values) ? $this->buildValues($value->values) : (string) $value;
109+
$data[] = isset($value->values) ? $this->buildValues($value->values) : XmlUtils::phpize($value->__toString());
113110
}
114111

115112
return $data;

tests/Metadata/Extractor/XmlExtractorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ public function testValidXML(): void
152152
],
153153
'normalizationContext' => [
154154
'groups' => ['comment:read', 'comment:custom-read'],
155+
'enabled' => true,
155156
],
156157
'denormalizationContext' => [
157158
'groups' => 'comment:write',
@@ -229,6 +230,7 @@ public function testValidXML(): void
229230
],
230231
'normalizationContext' => [
231232
'groups' => ['comment:read', 'comment:custom-read'],
233+
'enabled' => true,
232234
],
233235
'denormalizationContext' => [
234236
'groups' => 'comment:write',
@@ -321,6 +323,7 @@ public function testValidXML(): void
321323
],
322324
'normalizationContext' => [
323325
'groups' => ['comment:read', 'comment:custom-read'],
326+
'enabled' => true,
324327
],
325328
'denormalizationContext' => [
326329
'groups' => 'comment:write',

tests/Metadata/Extractor/YamlExtractorTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,10 @@ public function testValidYaml(): void
211211
'status' => null,
212212
'schemes' => null,
213213
'cacheHeaders' => null,
214-
'normalizationContext' => null,
214+
'normalizationContext' => [
215+
'groups' => ['foo', 'bar'],
216+
'enabled' => false,
217+
],
215218
'denormalizationContext' => null,
216219
'hydraContext' => null,
217220
'openapiContext' => null,
@@ -272,7 +275,10 @@ public function testValidYaml(): void
272275
'status' => null,
273276
'schemes' => null,
274277
'cacheHeaders' => null,
275-
'normalizationContext' => null,
278+
'normalizationContext' => [
279+
'groups' => ['foo', 'bar'],
280+
'enabled' => false,
281+
],
276282
'denormalizationContext' => null,
277283
'hydraContext' => null,
278284
'openapiContext' => null,
@@ -345,7 +351,10 @@ public function testValidYaml(): void
345351
'status' => null,
346352
'schemes' => null,
347353
'cacheHeaders' => null,
348-
'normalizationContext' => null,
354+
'normalizationContext' => [
355+
'groups' => ['foo', 'bar'],
356+
'enabled' => false,
357+
],
349358
'denormalizationContext' => null,
350359
'hydraContext' => null,
351360
'openapiContext' => null,

tests/Metadata/Extractor/xml/valid.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<value>comment:custom-read</value>
5454
</values>
5555
</value>
56+
<value name="enabled">true</value>
5657
</values>
5758
</normalizationContext>
5859

tests/Metadata/Extractor/yaml/valid.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ resources:
77
uriVariables: ['author']
88
types: ['someirischema']
99
description: User programs
10+
normalizationContext:
11+
groups: ['foo', 'bar']
12+
enabled: false
1013
operations:
1114
ApiPlatform\Metadata\GetCollection: ~
1215
ApiPlatform\Metadata\Get:

0 commit comments

Comments
 (0)