[Routing] added support for hostname in the XML loader
This commit is contained in:
parent
3dfca47bcd
commit
68da6ad292
@ -76,6 +76,7 @@ class XmlFileLoader extends FileLoader
|
||||
$resource = (string) $node->getAttribute('resource');
|
||||
$type = (string) $node->getAttribute('type');
|
||||
$prefix = (string) $node->getAttribute('prefix');
|
||||
$hostnamePattern = (string) $node->getAttribute('hostname-pattern');
|
||||
|
||||
$defaults = array();
|
||||
$requirements = array();
|
||||
@ -102,7 +103,7 @@ class XmlFileLoader extends FileLoader
|
||||
}
|
||||
|
||||
$this->setCurrentDir(dirname($path));
|
||||
$collection->addCollection($this->import($resource, ('' !== $type ? $type : null), false, $file), $prefix, $defaults, $requirements, $options);
|
||||
$collection->addCollection($this->import($resource, ('' !== $type ? $type : null), false, $file), $prefix, $defaults, $requirements, $options, $hostnamePattern);
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException(sprintf('Unable to parse tag "%s"', $node->tagName));
|
||||
@ -154,7 +155,7 @@ class XmlFileLoader extends FileLoader
|
||||
}
|
||||
}
|
||||
|
||||
$route = new Route((string) $definition->getAttribute('pattern'), $defaults, $requirements, $options);
|
||||
$route = new Route((string) $definition->getAttribute('pattern'), $defaults, $requirements, $options, (string) $definition->getAttribute('hostname-pattern'));
|
||||
|
||||
$collection->add((string) $definition->getAttribute('id'), $route);
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
<xsd:attribute name="id" type="xsd:string" />
|
||||
<xsd:attribute name="pattern" type="xsd:string" />
|
||||
<xsd:attribute name="hostname-pattern" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="import">
|
||||
@ -36,6 +37,7 @@
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="prefix" type="xsd:string" />
|
||||
<xsd:attribute name="class" type="xsd:string" />
|
||||
<xsd:attribute name="hostname-pattern" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="element" mixed="true">
|
||||
|
@ -4,7 +4,7 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
|
||||
|
||||
<route id="blog_show" pattern="/blog/{slug}">
|
||||
<route id="blog_show" pattern="/blog/{slug}" hostname-pattern="{locale}.example.com">
|
||||
<default key="_controller">MyBundle:Blog:show</default>
|
||||
<requirement key="_method">GET</requirement>
|
||||
<option key="compiler_class">RouteCompiler</option>
|
||||
|
@ -4,7 +4,7 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
|
||||
|
||||
<import resource="validpattern.xml" prefix="/{foo}">
|
||||
<import resource="validpattern.xml" prefix="/{foo}" hostname-pattern="{locale}.example.com">
|
||||
<default key="foo">foo</default>
|
||||
<requirement key="foo">\d+</requirement>
|
||||
<option key="foo">bar</option>
|
||||
|
@ -48,6 +48,10 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(1, count($routes), 'One route is loaded');
|
||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||
$route = $routes['blog_show'];
|
||||
$this->assertEquals('/blog/{slug}', $route->getPattern());
|
||||
$this->assertEquals('MyBundle:Blog:show', $route->getDefault('_controller'));
|
||||
$this->assertEquals('GET', $route->getRequirement('_method'));
|
||||
$this->assertEquals('{locale}.example.com', $route->getHostnamePattern());
|
||||
$this->assertEquals('RouteCompiler', $route->getOption('compiler_class'));
|
||||
}
|
||||
|
||||
@ -59,9 +63,12 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertEquals(1, count($routes), 'One route is loaded');
|
||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||
$this->assertEquals('/{foo}/blog/{slug}', $routes['blog_show']->getPattern());
|
||||
$this->assertEquals('MyBundle:Blog:show', $routes['blog_show']->getDefault('_controller'));
|
||||
$this->assertEquals('foo', $routes['blog_show']->getDefault('foo'));
|
||||
$this->assertEquals('\d+', $routes['blog_show']->getRequirement('foo'));
|
||||
$this->assertEquals('bar', $routes['blog_show']->getOption('foo'));
|
||||
$this->assertEquals('{locale}.example.com', $routes['blog_show']->getHostnamePattern());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user