Skip to content

Commit

Permalink
[Routing][XML Loader] Add a possibility to set a default value to null
Browse files Browse the repository at this point in the history
  • Loading branch information
aitboudad committed Apr 11, 2013
1 parent fb83589 commit 94a9cdc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Symfony/Component/Routing/Loader/XmlFileLoader.php
Expand Up @@ -141,7 +141,11 @@ protected function parseRoute(RouteCollection $collection, \DOMElement $definiti

switch ($node->tagName) {
case 'default':
$defaults[(string) $node->getAttribute('key')] = trim((string) $node->nodeValue);
if ($node->hasAttribute('xsi:nil') && 'true' == $node->getAttribute('xsi:nil')) {
$defaults[(string) $node->getAttribute('key')] = null;
} else {
$defaults[(string) $node->getAttribute('key')] = trim((string) $node->nodeValue);
}
break;
case 'option':
$options[(string) $node->getAttribute('key')] = trim((string) $node->nodeValue);
Expand Down
Expand Up @@ -16,7 +16,7 @@

<xsd:complexType name="route">
<xsd:sequence>
<xsd:element name="default" type="element" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="default" nillable="true" type="element" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="requirement" type="element" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="option" type="element" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
Expand Down
Expand Up @@ -6,6 +6,7 @@

<route id="blog_show" pattern="/blog/{slug}">
<default key="_controller">MyBundle:Blog:show</default>
<default key="slug" xsi:nil="true" />
<requirement key="_method">GET</requirement>
<option key="compiler_class">RouteCompiler</option>
</route>
Expand Down
Expand Up @@ -47,7 +47,9 @@ public function testLoadWithRoute()

$this->assertEquals(1, count($routes), 'One route is loaded');
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);

$route = $routes['blog_show'];
$this->assertSame(null, $route->getDefault('slug'));
$this->assertEquals('RouteCompiler', $route->getOption('compiler_class'));
}

Expand Down

0 comments on commit 94a9cdc

Please sign in to comment.