Skip to content

Commit 8b868df

Browse files
committed
#718 - XML options
1 parent 7257baa commit 8b868df

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

Routing/Loader/RestXmlCollectionLoader.php

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,6 @@ protected function parseNode(RouteCollection $collection, \DOMElement $node, $pa
103103
*/
104104
protected function parseRoute(RouteCollection $collection, \DOMElement $node, $path)
105105
{
106-
foreach ($node->childNodes as $child) {
107-
if ($child instanceof \DOMElement && $child->tagName === 'option') {
108-
$option = $node->ownerDocument->createElementNs(
109-
self::NAMESPACE_URI,
110-
'option',
111-
$child->nodeValue
112-
);
113-
$option->setAttribute('key', $child->getAttribute('key'));
114-
$node->appendChild($option);
115-
}
116-
}
117106

118107
// the Symfony Routing component uses a path attribute since Symfony 2.2
119108
// instead of the deprecated pattern attribute0
@@ -162,9 +151,33 @@ protected function parseRoute(RouteCollection $collection, \DOMElement $node, $p
162151
$node->appendChild($defaultFormatNode);
163152
}
164153

154+
$options = $this->getOptions($node);
155+
156+
foreach ($options as $option) {
157+
$node->appendChild($option);
158+
}
159+
165160
parent::parseRoute($collection, $node, $path);
166161
}
167162

163+
private function getOptions(\DOMElement $node)
164+
{
165+
$options = array();
166+
foreach ($node->childNodes as $child) {
167+
if ($child instanceof \DOMElement && $child->tagName === 'option') {
168+
$option = $node->ownerDocument->createElementNs(
169+
self::NAMESPACE_URI,
170+
'option',
171+
$child->nodeValue
172+
);
173+
$option->setAttribute('key', $child->getAttribute('key'));
174+
$options[] = $option;
175+
}
176+
}
177+
178+
return $options;
179+
}
180+
168181
/**
169182
* {@inheritDoc}
170183
*/

Tests/Routing/Loader/RestXmlCollectionLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function testForwardOptions()
122122
);
123123

124124
foreach ($collection as $route) {
125-
$this->assertTrue($route->getOption('expose'));
125+
$this->assertTrue('true' === $route->getOption('expose'));
126126
}
127127
}
128128
/**

0 commit comments

Comments
 (0)