Skip to content

Commit 3bc4086

Browse files
Merge branch '6.4' into 7.1
* 6.4: Work around parse_url() bug (bis) 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 66a2c46 + 99a4c49 commit 3bc4086

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: annotation
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(new AnnotationReader(), null) extends AnnotationClassLoader {
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)