diff --git a/src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php b/src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php
index 4591a86ba5cf9..d992cef843975 100644
--- a/src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php
+++ b/src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php
@@ -39,9 +39,17 @@ public function __construct(RouteCollection $collection, PhpFileLoader $loader,
final public function import($resource, $type = null, $ignoreErrors = false)
{
$this->loader->setCurrentDir(dirname($this->path));
- $subCollection = $this->loader->import($resource, $type, $ignoreErrors, $this->file);
+ $imported = $this->loader->import($resource, $type, $ignoreErrors, $this->file);
+ if (!is_array($imported)) {
+ return new ImportConfigurator($this->collection, $imported);
+ }
- return new ImportConfigurator($this->collection, $subCollection);
+ $mergedCollection = new RouteCollection();
+ foreach ($imported as $subCollection) {
+ $mergedCollection->addCollection($subCollection);
+ }
+
+ return new ImportConfigurator($this->collection, $mergedCollection);
}
/**
diff --git a/src/Symfony/Component/Routing/Loader/XmlFileLoader.php b/src/Symfony/Component/Routing/Loader/XmlFileLoader.php
index 3a77890703ce2..f3f66055e675a 100644
--- a/src/Symfony/Component/Routing/Loader/XmlFileLoader.php
+++ b/src/Symfony/Component/Routing/Loader/XmlFileLoader.php
@@ -146,26 +146,33 @@ protected function parseImport(RouteCollection $collection, \DOMElement $node, $
$this->setCurrentDir(dirname($path));
- $subCollection = $this->import($resource, ('' !== $type ? $type : null), false, $file);
- /* @var $subCollection RouteCollection */
- $subCollection->addPrefix($prefix);
- if (null !== $host) {
- $subCollection->setHost($host);
- }
- if (null !== $condition) {
- $subCollection->setCondition($condition);
- }
- if (null !== $schemes) {
- $subCollection->setSchemes($schemes);
- }
- if (null !== $methods) {
- $subCollection->setMethods($methods);
+ $imported = $this->import($resource, ('' !== $type ? $type : null), false, $file);
+
+ if (!is_array($imported)) {
+ $imported = array($imported);
}
- $subCollection->addDefaults($defaults);
- $subCollection->addRequirements($requirements);
- $subCollection->addOptions($options);
- $collection->addCollection($subCollection);
+ foreach ($imported as $subCollection) {
+ /* @var $subCollection RouteCollection */
+ $subCollection->addPrefix($prefix);
+ if (null !== $host) {
+ $subCollection->setHost($host);
+ }
+ if (null !== $condition) {
+ $subCollection->setCondition($condition);
+ }
+ if (null !== $schemes) {
+ $subCollection->setSchemes($schemes);
+ }
+ if (null !== $methods) {
+ $subCollection->setMethods($methods);
+ }
+ $subCollection->addDefaults($defaults);
+ $subCollection->addRequirements($requirements);
+ $subCollection->addOptions($options);
+
+ $collection->addCollection($subCollection);
+ }
}
/**
diff --git a/src/Symfony/Component/Routing/Loader/YamlFileLoader.php b/src/Symfony/Component/Routing/Loader/YamlFileLoader.php
index 037d581d05eab..f59f9097f6c6d 100644
--- a/src/Symfony/Component/Routing/Loader/YamlFileLoader.php
+++ b/src/Symfony/Component/Routing/Loader/YamlFileLoader.php
@@ -158,26 +158,33 @@ protected function parseImport(RouteCollection $collection, array $config, $path
$this->setCurrentDir(dirname($path));
- $subCollection = $this->import($config['resource'], $type, false, $file);
- /* @var $subCollection RouteCollection */
- $subCollection->addPrefix($prefix);
- if (null !== $host) {
- $subCollection->setHost($host);
- }
- if (null !== $condition) {
- $subCollection->setCondition($condition);
- }
- if (null !== $schemes) {
- $subCollection->setSchemes($schemes);
- }
- if (null !== $methods) {
- $subCollection->setMethods($methods);
+ $imported = $this->import($config['resource'], $type, false, $file);
+
+ if (!is_array($imported)) {
+ $imported = array($imported);
}
- $subCollection->addDefaults($defaults);
- $subCollection->addRequirements($requirements);
- $subCollection->addOptions($options);
- $collection->addCollection($subCollection);
+ foreach ($imported as $subCollection) {
+ /* @var $subCollection RouteCollection */
+ $subCollection->addPrefix($prefix);
+ if (null !== $host) {
+ $subCollection->setHost($host);
+ }
+ if (null !== $condition) {
+ $subCollection->setCondition($condition);
+ }
+ if (null !== $schemes) {
+ $subCollection->setSchemes($schemes);
+ }
+ if (null !== $methods) {
+ $subCollection->setMethods($methods);
+ }
+ $subCollection->addDefaults($defaults);
+ $subCollection->addRequirements($requirements);
+ $subCollection->addOptions($options);
+
+ $collection->addCollection($subCollection);
+ }
}
/**
diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/glob/bar.xml b/src/Symfony/Component/Routing/Tests/Fixtures/glob/bar.xml
new file mode 100644
index 0000000000000..0d31eeb178fc9
--- /dev/null
+++ b/src/Symfony/Component/Routing/Tests/Fixtures/glob/bar.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/glob/bar.yml b/src/Symfony/Component/Routing/Tests/Fixtures/glob/bar.yml
new file mode 100644
index 0000000000000..ba3bc2294b340
--- /dev/null
+++ b/src/Symfony/Component/Routing/Tests/Fixtures/glob/bar.yml
@@ -0,0 +1,4 @@
+bar_route:
+ path: /bar
+ defaults:
+ _controller: AppBundle:Bar:view
diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/glob/baz.xml b/src/Symfony/Component/Routing/Tests/Fixtures/glob/baz.xml
new file mode 100644
index 0000000000000..3abba1acede10
--- /dev/null
+++ b/src/Symfony/Component/Routing/Tests/Fixtures/glob/baz.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/glob/baz.yml b/src/Symfony/Component/Routing/Tests/Fixtures/glob/baz.yml
new file mode 100644
index 0000000000000..f7d8c67f266a8
--- /dev/null
+++ b/src/Symfony/Component/Routing/Tests/Fixtures/glob/baz.yml
@@ -0,0 +1,4 @@
+baz_route:
+ path: /baz
+ defaults:
+ _controller: AppBundle:Baz:view
diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/glob/import_multiple.xml b/src/Symfony/Component/Routing/Tests/Fixtures/glob/import_multiple.xml
new file mode 100644
index 0000000000000..ca6b1b5a927bb
--- /dev/null
+++ b/src/Symfony/Component/Routing/Tests/Fixtures/glob/import_multiple.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/glob/import_multiple.yml b/src/Symfony/Component/Routing/Tests/Fixtures/glob/import_multiple.yml
new file mode 100644
index 0000000000000..d1ae5854a51c1
--- /dev/null
+++ b/src/Symfony/Component/Routing/Tests/Fixtures/glob/import_multiple.yml
@@ -0,0 +1,2 @@
+_static:
+ resource: ba?.yml
diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/glob/import_single.xml b/src/Symfony/Component/Routing/Tests/Fixtures/glob/import_single.xml
new file mode 100644
index 0000000000000..15f5698ccd712
--- /dev/null
+++ b/src/Symfony/Component/Routing/Tests/Fixtures/glob/import_single.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/glob/import_single.yml b/src/Symfony/Component/Routing/Tests/Fixtures/glob/import_single.yml
new file mode 100644
index 0000000000000..f56ddbd0be9f7
--- /dev/null
+++ b/src/Symfony/Component/Routing/Tests/Fixtures/glob/import_single.yml
@@ -0,0 +1,2 @@
+_static:
+ resource: b?r.yml
diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/glob/php_dsl.php b/src/Symfony/Component/Routing/Tests/Fixtures/glob/php_dsl.php
new file mode 100644
index 0000000000000..897fa11f282af
--- /dev/null
+++ b/src/Symfony/Component/Routing/Tests/Fixtures/glob/php_dsl.php
@@ -0,0 +1,7 @@
+import('php_dsl_ba?.php');
+};
diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/glob/php_dsl_bar.php b/src/Symfony/Component/Routing/Tests/Fixtures/glob/php_dsl_bar.php
new file mode 100644
index 0000000000000..e2b91b17da490
--- /dev/null
+++ b/src/Symfony/Component/Routing/Tests/Fixtures/glob/php_dsl_bar.php
@@ -0,0 +1,12 @@
+collection();
+
+ $collection->add('bar_route', '/bar')
+ ->defaults(array('_controller' => 'AppBundle:Bar:view'));
+
+ return $collection;
+};
diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/glob/php_dsl_baz.php b/src/Symfony/Component/Routing/Tests/Fixtures/glob/php_dsl_baz.php
new file mode 100644
index 0000000000000..ca8f188a7633e
--- /dev/null
+++ b/src/Symfony/Component/Routing/Tests/Fixtures/glob/php_dsl_baz.php
@@ -0,0 +1,12 @@
+collection();
+
+ $collection->add('baz_route', '/baz')
+ ->defaults(array('_controller' => 'AppBundle:Baz:view'));
+
+ return $collection;
+};
diff --git a/src/Symfony/Component/Routing/Tests/Loader/PhpFileLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/PhpFileLoaderTest.php
index 608d84ed7a20f..0dcf5d4941bef 100644
--- a/src/Symfony/Component/Routing/Tests/Loader/PhpFileLoaderTest.php
+++ b/src/Symfony/Component/Routing/Tests/Loader/PhpFileLoaderTest.php
@@ -117,4 +117,17 @@ public function testRoutingConfigurator()
$this->assertEquals($expectedCollection, $routeCollection);
}
+
+ public function testRoutingConfiguratorCanImportGlobPatterns()
+ {
+ $locator = new FileLocator(array(__DIR__.'/../Fixtures/glob'));
+ $loader = new PhpFileLoader($locator);
+ $routeCollection = $loader->load('php_dsl.php');
+
+ $route = $routeCollection->get('bar_route');
+ $this->assertSame('AppBundle:Bar:view', $route->getDefault('_controller'));
+
+ $route = $routeCollection->get('baz_route');
+ $this->assertSame('AppBundle:Baz:view', $route->getDefault('_controller'));
+ }
}
diff --git a/src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php
index 221434b0068aa..21fc3400f249e 100644
--- a/src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php
+++ b/src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php
@@ -361,4 +361,25 @@ public function testImportWithOverriddenController()
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
$loader->load('import_override_defaults.xml');
}
+
+ public function testImportRouteWithGlobMatchingSingleFile()
+ {
+ $loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/glob')));
+ $routeCollection = $loader->load('import_single.xml');
+
+ $route = $routeCollection->get('bar_route');
+ $this->assertSame('AppBundle:Bar:view', $route->getDefault('_controller'));
+ }
+
+ public function testImportRouteWithGlobMatchingMultipleFiles()
+ {
+ $loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/glob')));
+ $routeCollection = $loader->load('import_multiple.xml');
+
+ $route = $routeCollection->get('bar_route');
+ $this->assertSame('AppBundle:Bar:view', $route->getDefault('_controller'));
+
+ $route = $routeCollection->get('baz_route');
+ $this->assertSame('AppBundle:Baz:view', $route->getDefault('_controller'));
+ }
}
diff --git a/src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php
index 1f7fd43897ae3..822bddf1f0c34 100644
--- a/src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php
+++ b/src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php
@@ -182,4 +182,25 @@ public function testImportWithOverriddenController()
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
$loader->load('import_override_defaults.yml');
}
+
+ public function testImportRouteWithGlobMatchingSingleFile()
+ {
+ $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/glob')));
+ $routeCollection = $loader->load('import_single.yml');
+
+ $route = $routeCollection->get('bar_route');
+ $this->assertSame('AppBundle:Bar:view', $route->getDefault('_controller'));
+ }
+
+ public function testImportRouteWithGlobMatchingMultipleFiles()
+ {
+ $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/glob')));
+ $routeCollection = $loader->load('import_multiple.yml');
+
+ $route = $routeCollection->get('bar_route');
+ $this->assertSame('AppBundle:Bar:view', $route->getDefault('_controller'));
+
+ $route = $routeCollection->get('baz_route');
+ $this->assertSame('AppBundle:Baz:view', $route->getDefault('_controller'));
+ }
}
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy