Skip to content

Commit 40f0d28

Browse files
Merge branch '7.1' into 7.2
* 7.1: fix merge fix merge Bump Symfony version to 7.1.9 Work around parse_url() bug (bis) Update VERSION for 7.1.8 Update CHANGELOG for 7.1.8 Bump Symfony version to 6.4.16 fix PHP 7.2 compatibility silence PHP warnings issued by Redis::connect() Update VERSION for 6.4.15 Update CHANGELOG for 6.4.15 Bump Symfony version to 5.4.48 Update VERSION for 5.4.47 Update CHANGELOG for 5.4.47 [Routing] Fix: lost priority when defining hosts in configuration fix dumping tests to skip with data providers
2 parents 0782e32 + a27bb8e commit 40f0d28

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

Loader/Configurator/Traits/HostTrait.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,22 @@ final protected function addHost(RouteCollection $routes, string|array $hosts):
2828

2929
foreach ($routes->all() as $name => $route) {
3030
if (null === $locale = $route->getDefault('_locale')) {
31+
$priority = $routes->getPriority($name) ?? 0;
3132
$routes->remove($name);
3233
foreach ($hosts as $locale => $host) {
3334
$localizedRoute = clone $route;
3435
$localizedRoute->setDefault('_locale', $locale);
3536
$localizedRoute->setRequirement('_locale', preg_quote($locale));
3637
$localizedRoute->setDefault('_canonical_route', $name);
3738
$localizedRoute->setHost($host);
38-
$routes->add($name.'.'.$locale, $localizedRoute);
39+
$routes->add($name.'.'.$locale, $localizedRoute, $priority);
3940
}
4041
} elseif (!isset($hosts[$locale])) {
4142
throw new \InvalidArgumentException(\sprintf('Route "%s" with locale "%s" is missing a corresponding host in its parent collection.', $name, $locale));
4243
} else {
4344
$route->setHost($hosts[$locale]);
4445
$route->setRequirement('_locale', preg_quote($locale));
45-
$routes->add($name, $route);
46+
$routes->add($name, $route, $routes->getPriority($name) ?? 0);
4647
}
4748
}
4849
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
controllers:
2+
resource: Symfony\Component\Routing\Tests\Fixtures\AttributeFixtures\RouteWithPriorityController
3+
type: attribute
4+
host:
5+
cs: www.domain.cs
6+
en: www.domain.com

Tests/Loader/YamlFileLoaderTest.php

+23
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,29 @@ protected function configureRoute(Route $route, \ReflectionClass $class, \Reflec
489489
$this->assertSame(1, $routes->getPriority('also_important'));
490490
}
491491

492+
public function testPriorityWithHost()
493+
{
494+
new LoaderResolver([
495+
$loader = new YamlFileLoader(new FileLocator(\dirname(__DIR__).'/Fixtures/locale_and_host')),
496+
new class() extends AttributeClassLoader {
497+
protected function configureRoute(
498+
Route $route,
499+
\ReflectionClass $class,
500+
\ReflectionMethod $method,
501+
object $annot
502+
): void {
503+
$route->setDefault('_controller', $class->getName().'::'.$method->getName());
504+
}
505+
},
506+
]);
507+
508+
$routes = $loader->load('priorized-host.yml');
509+
510+
$this->assertSame(2, $routes->getPriority('important.cs'));
511+
$this->assertSame(2, $routes->getPriority('important.en'));
512+
$this->assertSame(1, $routes->getPriority('also_important'));
513+
}
514+
492515
/**
493516
* @dataProvider providePsr4ConfigFiles
494517
*/

0 commit comments

Comments
 (0)