Skip to content

Commit 7257baa

Browse files
committed
#718 - XML route options
1 parent ada8e19 commit 7257baa

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

Routing/Loader/RestXmlCollectionLoader.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ 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+
}
117+
106118
// the Symfony Routing component uses a path attribute since Symfony 2.2
107119
// instead of the deprecated pattern attribute0
108120
if (!$node->hasAttribute('path')) {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<routes xmlns="http://friendsofsymfony.github.com/schema/rest"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://friendsofsymfony.github.com/schema/rest
5+
http://friendsofsymfony.github.com/schema/rest/routing-1.0.xsd"
6+
>
7+
<route id="get_users" pattern="/users">
8+
<default key="_controller">FOSRestBundle:UsersController:getUsers</default>
9+
<option key="expose">true</option>
10+
</route>
11+
</routes>

Tests/Routing/Loader/RestXmlCollectionLoaderTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,23 @@ public function testManualRoutesWithDefaultFormat()
108108
$this->assertEquals('xml', $route->getDefault('_format'));
109109
}
110110

111+
public function testForwardOptions()
112+
{
113+
$collection = $this->loadFromXmlCollectionFixture(
114+
'routes_with_options.xml',
115+
true,
116+
array(
117+
'json' => false,
118+
'xml' => false,
119+
'html' => true,
120+
),
121+
'xml'
122+
);
123+
124+
foreach ($collection as $route) {
125+
$this->assertTrue($route->getOption('expose'));
126+
}
127+
}
111128
/**
112129
* Load routes collection from XML fixture routes under Tests\Fixtures directory.
113130
*

0 commit comments

Comments
 (0)