Skip to content

Commit 94a9cdc

Browse files
committed
[Routing][XML Loader] Add a possibility to set a default value to null
1 parent fb83589 commit 94a9cdc

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

src/Symfony/Component/Routing/Loader/XmlFileLoader.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,11 @@ protected function parseRoute(RouteCollection $collection, \DOMElement $definiti
141141

142142
switch ($node->tagName) {
143143
case 'default':
144-
$defaults[(string) $node->getAttribute('key')] = trim((string) $node->nodeValue);
144+
if ($node->hasAttribute('xsi:nil') && 'true' == $node->getAttribute('xsi:nil')) {
145+
$defaults[(string) $node->getAttribute('key')] = null;
146+
} else {
147+
$defaults[(string) $node->getAttribute('key')] = trim((string) $node->nodeValue);
148+
}
145149
break;
146150
case 'option':
147151
$options[(string) $node->getAttribute('key')] = trim((string) $node->nodeValue);

src/Symfony/Component/Routing/Loader/schema/routing/routing-1.0.xsd

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<xsd:complexType name="route">
1818
<xsd:sequence>
19-
<xsd:element name="default" type="element" minOccurs="0" maxOccurs="unbounded" />
19+
<xsd:element name="default" nillable="true" type="element" minOccurs="0" maxOccurs="unbounded" />
2020
<xsd:element name="requirement" type="element" minOccurs="0" maxOccurs="unbounded" />
2121
<xsd:element name="option" type="element" minOccurs="0" maxOccurs="unbounded" />
2222
</xsd:sequence>

src/Symfony/Component/Routing/Tests/Fixtures/validpattern.xml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<route id="blog_show" pattern="/blog/{slug}">
88
<default key="_controller">MyBundle:Blog:show</default>
9+
<default key="slug" xsi:nil="true" />
910
<requirement key="_method">GET</requirement>
1011
<option key="compiler_class">RouteCompiler</option>
1112
</route>

src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ public function testLoadWithRoute()
4747

4848
$this->assertEquals(1, count($routes), 'One route is loaded');
4949
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
50+
5051
$route = $routes['blog_show'];
52+
$this->assertSame(null, $route->getDefault('slug'));
5153
$this->assertEquals('RouteCompiler', $route->getOption('compiler_class'));
5254
}
5355

0 commit comments

Comments
 (0)