From 94a9cdc473e70b6aa818e9772a552e3ddec536d5 Mon Sep 17 00:00:00 2001 From: Abdellatif Ait boudad Date: Thu, 11 Apr 2013 23:37:28 +0000 Subject: [PATCH] [Routing][XML Loader] Add a possibility to set a default value to null --- src/Symfony/Component/Routing/Loader/XmlFileLoader.php | 6 +++++- .../Component/Routing/Loader/schema/routing/routing-1.0.xsd | 2 +- .../Component/Routing/Tests/Fixtures/validpattern.xml | 1 + .../Component/Routing/Tests/Loader/XmlFileLoaderTest.php | 2 ++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Routing/Loader/XmlFileLoader.php b/src/Symfony/Component/Routing/Loader/XmlFileLoader.php index 695494bd6e1a..9d4da3d096dc 100644 --- a/src/Symfony/Component/Routing/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/XmlFileLoader.php @@ -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); diff --git a/src/Symfony/Component/Routing/Loader/schema/routing/routing-1.0.xsd b/src/Symfony/Component/Routing/Loader/schema/routing/routing-1.0.xsd index 826dfc9c369f..af642d846e41 100644 --- a/src/Symfony/Component/Routing/Loader/schema/routing/routing-1.0.xsd +++ b/src/Symfony/Component/Routing/Loader/schema/routing/routing-1.0.xsd @@ -16,7 +16,7 @@ - + diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/validpattern.xml b/src/Symfony/Component/Routing/Tests/Fixtures/validpattern.xml index fdb38073a0ea..740224c0d238 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/validpattern.xml +++ b/src/Symfony/Component/Routing/Tests/Fixtures/validpattern.xml @@ -6,6 +6,7 @@ MyBundle:Blog:show + GET diff --git a/src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php index e6f217606da4..147b6e70a747 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php @@ -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')); }