Skip to content

Commit 0c669dd

Browse files
Merge branch '4.0'
* 4.0: (24 commits) moved Twig runtime to proper class fixed deprecated messages in tests add PHP errors options to XML schema definition [HttpCache] Unlink tmp file on error Added LB translation for #26327 (Errors sign for people that do not see colors) [TwigBridge] Fix rendering of currency by MoneyType Import InvalidArgumentException in PdoAdapter [DI] Do not suggest writing an implementation when multiple exist [Intl] Update ICU data to 61.1 Use 3rd person verb form in command description [Validator] Add Japanese translation Support phpdbg SAPI in Debug::enable() [HttpKernel] DumpDataCollector: do not flush when a dumper is provided [DI] Fix hardcoded cache dir for warmups [Routing] fix tests [Routing] Fixed the importing of files using glob patterns that match multiple resources [Ldap] cast to string when checking empty passwords [Validator] sync validator translation id [WebProfilerBundle] use the router to resolve file links no type errors with invalid submitted data types ...
2 parents b97a818 + ca780c8 commit 0c669dd

18 files changed

+250
-101
lines changed

Loader/Configurator/RoutingConfigurator.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,17 @@ public function __construct(RouteCollection $collection, PhpFileLoader $loader,
3939
final public function import($resource, $type = null, $ignoreErrors = false)
4040
{
4141
$this->loader->setCurrentDir(dirname($this->path));
42-
$subCollection = $this->loader->import($resource, $type, $ignoreErrors, $this->file);
42+
$imported = $this->loader->import($resource, $type, $ignoreErrors, $this->file);
43+
if (!is_array($imported)) {
44+
return new ImportConfigurator($this->collection, $imported);
45+
}
4346

44-
return new ImportConfigurator($this->collection, $subCollection);
47+
$mergedCollection = new RouteCollection();
48+
foreach ($imported as $subCollection) {
49+
$mergedCollection->addCollection($subCollection);
50+
}
51+
52+
return new ImportConfigurator($this->collection, $mergedCollection);
4553
}
4654

4755
/**

Loader/XmlFileLoader.php

Lines changed: 52 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -168,63 +168,66 @@ protected function parseImport(RouteCollection $collection, \DOMElement $node, $
168168

169169
$this->setCurrentDir(dirname($path));
170170

171-
/* @var $subCollection RouteCollection */
172-
$subCollection = $this->import($resource, ('' !== $type ? $type : null), false, $file);
173-
174-
if ('' !== $prefix || !$prefixes) {
175-
$subCollection->addPrefix($prefix);
176-
if (!$trailingSlashOnRoot) {
177-
$rootPath = (new Route(trim(trim($prefix), '/').'/'))->getPath();
178-
foreach ($subCollection->all() as $route) {
179-
if ($route->getPath() === $rootPath) {
180-
$route->setPath(rtrim($rootPath, '/'));
171+
$imported = $this->import($resource, ('' !== $type ? $type : null), false, $file);
172+
173+
if (!is_array($imported)) {
174+
$imported = array($imported);
175+
}
176+
177+
foreach ($imported as $subCollection) {
178+
/* @var $subCollection RouteCollection */
179+
if ('' !== $prefix || !$prefixes) {
180+
$subCollection->addPrefix($prefix);
181+
if (!$trailingSlashOnRoot) {
182+
$rootPath = (new Route(trim(trim($prefix), '/').'/'))->getPath();
183+
foreach ($subCollection->all() as $route) {
184+
if ($route->getPath() === $rootPath) {
185+
$route->setPath(rtrim($rootPath, '/'));
186+
}
181187
}
182188
}
183-
}
184-
} else {
185-
foreach ($prefixes as $locale => $localePrefix) {
186-
$prefixes[$locale] = trim(trim($localePrefix), '/');
187-
}
188-
foreach ($subCollection->all() as $name => $route) {
189-
if (null === $locale = $route->getDefault('_locale')) {
190-
$subCollection->remove($name);
191-
foreach ($prefixes as $locale => $localePrefix) {
192-
$localizedRoute = clone $route;
193-
$localizedRoute->setPath($localePrefix.(!$trailingSlashOnRoot && '/' === $route->getPath() ? '' : $route->getPath()));
194-
$localizedRoute->setDefault('_locale', $locale);
195-
$localizedRoute->setDefault('_canonical_route', $name);
196-
$subCollection->add($name.'.'.$locale, $localizedRoute);
189+
} else {
190+
foreach ($prefixes as $locale => $localePrefix) {
191+
$prefixes[$locale] = trim(trim($localePrefix), '/');
192+
}
193+
foreach ($subCollection->all() as $name => $route) {
194+
if (null === $locale = $route->getDefault('_locale')) {
195+
$subCollection->remove($name);
196+
foreach ($prefixes as $locale => $localePrefix) {
197+
$localizedRoute = clone $route;
198+
$localizedRoute->setPath($localePrefix.(!$trailingSlashOnRoot && '/' === $route->getPath() ? '' : $route->getPath()));
199+
$localizedRoute->setDefault('_locale', $locale);
200+
$localizedRoute->setDefault('_canonical_route', $name);
201+
$subCollection->add($name.'.'.$locale, $localizedRoute);
202+
}
203+
} elseif (!isset($prefixes[$locale])) {
204+
throw new \InvalidArgumentException(sprintf('Route "%s" with locale "%s" is missing a corresponding prefix when imported in "%s".', $name, $locale, $path));
205+
} else {
206+
$route->setPath($prefixes[$locale].(!$trailingSlashOnRoot && '/' === $route->getPath() ? '' : $route->getPath()));
207+
$subCollection->add($name, $route);
197208
}
198-
} elseif (!isset($prefixes[$locale])) {
199-
throw new \InvalidArgumentException(sprintf('Route "%s" with locale "%s" is missing a corresponding prefix when imported in "%s".', $name, $locale, $path));
200-
} else {
201-
$route->setPath($prefixes[$locale].(!$trailingSlashOnRoot && '/' === $route->getPath() ? '' : $route->getPath()));
202-
$subCollection->add($name, $route);
203209
}
204210
}
205-
}
206211

207-
if (null !== $host) {
208-
$subCollection->setHost($host);
209-
}
210-
if (null !== $condition) {
211-
$subCollection->setCondition($condition);
212-
}
213-
if (null !== $schemes) {
214-
$subCollection->setSchemes($schemes);
215-
}
216-
if (null !== $methods) {
217-
$subCollection->setMethods($methods);
218-
}
219-
$subCollection->addDefaults($defaults);
220-
$subCollection->addRequirements($requirements);
221-
$subCollection->addOptions($options);
212+
if (null !== $host) {
213+
$subCollection->setHost($host);
214+
}
215+
if (null !== $condition) {
216+
$subCollection->setCondition($condition);
217+
}
218+
if (null !== $schemes) {
219+
$subCollection->setSchemes($schemes);
220+
}
221+
if (null !== $methods) {
222+
$subCollection->setMethods($methods);
223+
}
222224

223-
if ($namePrefix = $node->getAttribute('name-prefix')) {
224-
$subCollection->addNamePrefix($namePrefix);
225-
}
225+
if ($namePrefix = $node->getAttribute('name-prefix')) {
226+
$subCollection->addNamePrefix($namePrefix);
227+
}
226228

227-
$collection->addCollection($subCollection);
229+
$collection->addCollection($subCollection);
230+
}
228231
}
229232

230233
/**

Loader/YamlFileLoader.php

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -163,63 +163,66 @@ protected function parseImport(RouteCollection $collection, array $config, $path
163163

164164
$this->setCurrentDir(dirname($path));
165165

166-
/** @var RouteCollection $subCollection */
167-
$subCollection = $this->import($config['resource'], $type, false, $file);
166+
$imported = $this->import($config['resource'], $type, false, $file);
168167

169-
if (!\is_array($prefix)) {
170-
$subCollection->addPrefix($prefix);
171-
if (!$trailingSlashOnRoot) {
172-
$rootPath = (new Route(trim(trim($prefix), '/').'/'))->getPath();
173-
foreach ($subCollection->all() as $route) {
174-
if ($route->getPath() === $rootPath) {
175-
$route->setPath(rtrim($rootPath, '/'));
168+
if (!is_array($imported)) {
169+
$imported = array($imported);
170+
}
171+
172+
foreach ($imported as $subCollection) {
173+
/* @var $subCollection RouteCollection */
174+
if (!\is_array($prefix)) {
175+
$subCollection->addPrefix($prefix);
176+
if (!$trailingSlashOnRoot) {
177+
$rootPath = (new Route(trim(trim($prefix), '/').'/'))->getPath();
178+
foreach ($subCollection->all() as $route) {
179+
if ($route->getPath() === $rootPath) {
180+
$route->setPath(rtrim($rootPath, '/'));
181+
}
176182
}
177183
}
178-
}
179-
} else {
180-
foreach ($prefix as $locale => $localePrefix) {
181-
$prefix[$locale] = trim(trim($localePrefix), '/');
182-
}
183-
foreach ($subCollection->all() as $name => $route) {
184-
if (null === $locale = $route->getDefault('_locale')) {
185-
$subCollection->remove($name);
186-
foreach ($prefix as $locale => $localePrefix) {
187-
$localizedRoute = clone $route;
188-
$localizedRoute->setDefault('_locale', $locale);
189-
$localizedRoute->setDefault('_canonical_route', $name);
190-
$localizedRoute->setPath($localePrefix.(!$trailingSlashOnRoot && '/' === $route->getPath() ? '' : $route->getPath()));
191-
$subCollection->add($name.'.'.$locale, $localizedRoute);
184+
} else {
185+
foreach ($prefix as $locale => $localePrefix) {
186+
$prefix[$locale] = trim(trim($localePrefix), '/');
187+
}
188+
foreach ($subCollection->all() as $name => $route) {
189+
if (null === $locale = $route->getDefault('_locale')) {
190+
$subCollection->remove($name);
191+
foreach ($prefix as $locale => $localePrefix) {
192+
$localizedRoute = clone $route;
193+
$localizedRoute->setDefault('_locale', $locale);
194+
$localizedRoute->setDefault('_canonical_route', $name);
195+
$localizedRoute->setPath($localePrefix.(!$trailingSlashOnRoot && '/' === $route->getPath() ? '' : $route->getPath()));
196+
$subCollection->add($name.'.'.$locale, $localizedRoute);
197+
}
198+
} elseif (!isset($prefix[$locale])) {
199+
throw new \InvalidArgumentException(sprintf('Route "%s" with locale "%s" is missing a corresponding prefix when imported in "%s".', $name, $locale, $file));
200+
} else {
201+
$route->setPath($prefix[$locale].(!$trailingSlashOnRoot && '/' === $route->getPath() ? '' : $route->getPath()));
202+
$subCollection->add($name, $route);
192203
}
193-
} elseif (!isset($prefix[$locale])) {
194-
throw new \InvalidArgumentException(sprintf('Route "%s" with locale "%s" is missing a corresponding prefix when imported in "%s".', $name, $locale, $file));
195-
} else {
196-
$route->setPath($prefix[$locale].(!$trailingSlashOnRoot && '/' === $route->getPath() ? '' : $route->getPath()));
197-
$subCollection->add($name, $route);
198204
}
199205
}
200-
}
201206

202-
if (null !== $host) {
203-
$subCollection->setHost($host);
204-
}
205-
if (null !== $condition) {
206-
$subCollection->setCondition($condition);
207-
}
208-
if (null !== $schemes) {
209-
$subCollection->setSchemes($schemes);
210-
}
211-
if (null !== $methods) {
212-
$subCollection->setMethods($methods);
213-
}
214-
$subCollection->addDefaults($defaults);
215-
$subCollection->addRequirements($requirements);
216-
$subCollection->addOptions($options);
207+
if (null !== $host) {
208+
$subCollection->setHost($host);
209+
}
210+
if (null !== $condition) {
211+
$subCollection->setCondition($condition);
212+
}
213+
if (null !== $schemes) {
214+
$subCollection->setSchemes($schemes);
215+
}
216+
if (null !== $methods) {
217+
$subCollection->setMethods($methods);
218+
}
217219

218-
if (isset($config['name_prefix'])) {
219-
$subCollection->addNamePrefix($config['name_prefix']);
220-
}
220+
if (isset($config['name_prefix'])) {
221+
$subCollection->addNamePrefix($config['name_prefix']);
222+
}
221223

222-
$collection->addCollection($subCollection);
224+
$collection->addCollection($subCollection);
225+
}
223226
}
224227

225228
/**

Router.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,9 @@ function (ConfigCacheInterface $cache) {
302302
}
303303
);
304304

305-
require_once $cache->getPath();
305+
if (!class_exists($this->options['matcher_cache_class'], false)) {
306+
require_once $cache->getPath();
307+
}
306308

307309
return $this->matcher = new $this->options['matcher_cache_class']($this->context);
308310
}
@@ -334,7 +336,9 @@ function (ConfigCacheInterface $cache) {
334336
}
335337
);
336338

337-
require_once $cache->getPath();
339+
if (!class_exists($this->options['generator_cache_class'], false)) {
340+
require_once $cache->getPath();
341+
}
338342

339343
$this->generator = new $this->options['generator_cache_class']($this->context, $this->logger);
340344
}

Tests/Fixtures/glob/bar.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<routes xmlns="http://symfony.com/schema/routing"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/routing
5+
http://symfony.com/schema/routing/routing-1.0.xsd">
6+
7+
<route id="bar_route" path="/bar" controller="AppBundle:Bar:view" />
8+
</routes>

Tests/Fixtures/glob/bar.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bar_route:
2+
path: /bar
3+
defaults:
4+
_controller: AppBundle:Bar:view

Tests/Fixtures/glob/baz.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<routes xmlns="http://symfony.com/schema/routing"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/routing
5+
http://symfony.com/schema/routing/routing-1.0.xsd">
6+
7+
<route id="baz_route" path="/baz" controller="AppBundle:Baz:view" />
8+
</routes>

Tests/Fixtures/glob/baz.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
baz_route:
2+
path: /baz
3+
defaults:
4+
_controller: AppBundle:Baz:view
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<routes xmlns="http://symfony.com/schema/routing"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/routing
5+
http://symfony.com/schema/routing/routing-1.0.xsd">
6+
7+
<import resource="ba?.xml" />
8+
</routes>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
_static:
2+
resource: ba?.yml

0 commit comments

Comments
 (0)