merged branch Aitboudad/ticket__7335 (PR #7635)
This PR was merged into the 2.1 branch.
Discussion
----------
[Routing][XML Loader] Add a possibility to set a default value to null
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | https://github.com/symfony/symfony/issues/7335
| License | MIT
Example:
<route id="acme_user_show" pattern="/{id}">
<default key="_controller">AcmeUserBundle:User:show</default>
<default key="id" xsi:nil="true" />
</route>
Commits
-------
94a9cdc
[Routing][XML Loader] Add a possibility to set a default value to null
This commit is contained in:
commit
de275b5ba9
@ -141,7 +141,11 @@ class XmlFileLoader extends FileLoader
|
|||||||
|
|
||||||
switch ($node->tagName) {
|
switch ($node->tagName) {
|
||||||
case 'default':
|
case 'default':
|
||||||
|
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);
|
$defaults[(string) $node->getAttribute('key')] = trim((string) $node->nodeValue);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'option':
|
case 'option':
|
||||||
$options[(string) $node->getAttribute('key')] = trim((string) $node->nodeValue);
|
$options[(string) $node->getAttribute('key')] = trim((string) $node->nodeValue);
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
<xsd:complexType name="route">
|
<xsd:complexType name="route">
|
||||||
<xsd:sequence>
|
<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="requirement" type="element" minOccurs="0" maxOccurs="unbounded" />
|
||||||
<xsd:element name="option" type="element" minOccurs="0" maxOccurs="unbounded" />
|
<xsd:element name="option" type="element" minOccurs="0" maxOccurs="unbounded" />
|
||||||
</xsd:sequence>
|
</xsd:sequence>
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
<route id="blog_show" pattern="/blog/{slug}">
|
<route id="blog_show" pattern="/blog/{slug}">
|
||||||
<default key="_controller">MyBundle:Blog:show</default>
|
<default key="_controller">MyBundle:Blog:show</default>
|
||||||
|
<default key="slug" xsi:nil="true" />
|
||||||
<requirement key="_method">GET</requirement>
|
<requirement key="_method">GET</requirement>
|
||||||
<option key="compiler_class">RouteCompiler</option>
|
<option key="compiler_class">RouteCompiler</option>
|
||||||
</route>
|
</route>
|
||||||
|
@ -47,7 +47,9 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->assertEquals(1, count($routes), 'One route is loaded');
|
$this->assertEquals(1, count($routes), 'One route is loaded');
|
||||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||||
|
|
||||||
$route = $routes['blog_show'];
|
$route = $routes['blog_show'];
|
||||||
|
$this->assertSame(null, $route->getDefault('slug'));
|
||||||
$this->assertEquals('RouteCompiler', $route->getOption('compiler_class'));
|
$this->assertEquals('RouteCompiler', $route->getOption('compiler_class'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user