Skip to content

Commit ee9a67e

Browse files
committed
Merge branch '7.1' into 7.2
* 7.1: (34 commits) improve amqp connection issues [Serializer] [ObjectNormalizer] Filter int when using FILTER_BOOL Fix #53778 [PropertyInfo] Add missing test fix tests [Security][Validators] Review translations. [validator] Updated Dutch translation [FrameworkBundle] Fix wiring ConsoleProfilerListener [HttpKernel] Fix link to php doc [Validator] Update sr_Cyrl 120:This value is not a valid slug. [Validator] Update sr_Latn 120:This value is not a valid slug. 6.4 Missing translations for Italian (it) #59419 tests(notifier): avoid failing SNS test with local AWS configuration Fix typo ratio comment chore: PropertyAccess - fix typo in DocBlock [Validator] Missing translations for Brazilian Portuguese (pt_BR) fix(dependency-injection): reset env vars with kernel.reset [Translation][Validator] Review Russian translation (114 - 120) Review validator-related persian translation with id 120 [Scheduler] Clarify description of exclusion time ...
2 parents e10a245 + 07f6463 commit ee9a67e

10 files changed

+92
-2
lines changed

Loader/Configurator/RouteConfigurator.php

+7
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ public function __construct(
4444
*/
4545
final public function host(string|array $host): static
4646
{
47+
$previousRoutes = clone $this->route;
4748
$this->addHost($this->route, $host);
49+
foreach ($previousRoutes as $name => $route) {
50+
if (!$this->route->get($name)) {
51+
$this->collection->remove($name);
52+
}
53+
}
54+
$this->collection->addCollection($this->route);
4855

4956
return $this;
5057
}

Loader/XmlFileLoader.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ protected function parseRoute(RouteCollection $collection, \DOMElement $node, st
131131
throw new \InvalidArgumentException(\sprintf('The <route> element in file "%s" must not have both a "path" attribute and <path> child nodes.', $path));
132132
}
133133

134-
$routes = $this->createLocalizedRoute($collection, $id, $paths ?: $node->getAttribute('path'));
134+
$routes = $this->createLocalizedRoute(new RouteCollection(), $id, $paths ?: $node->getAttribute('path'));
135135
$routes->addDefaults($defaults);
136136
$routes->addRequirements($requirements);
137137
$routes->addOptions($options);
@@ -142,6 +142,8 @@ protected function parseRoute(RouteCollection $collection, \DOMElement $node, st
142142
if (null !== $hosts) {
143143
$this->addHost($routes, $hosts);
144144
}
145+
146+
$collection->addCollection($routes);
145147
}
146148

147149
/**

Loader/YamlFileLoader.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ protected function parseRoute(RouteCollection $collection, string $name, array $
155155
$defaults['_stateless'] = $config['stateless'];
156156
}
157157

158-
$routes = $this->createLocalizedRoute($collection, $name, $config['path']);
158+
$routes = $this->createLocalizedRoute(new RouteCollection(), $name, $config['path']);
159159
$routes->addDefaults($defaults);
160160
$routes->addRequirements($requirements);
161161
$routes->addOptions($options);
@@ -166,6 +166,8 @@ protected function parseRoute(RouteCollection $collection, string $name, array $
166166
if (isset($config['host'])) {
167167
$this->addHost($routes, $config['host']);
168168
}
169+
170+
$collection->addCollection($routes);
169171
}
170172

171173
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
use Symfony\Component\Config\Resource\FileResource;
4+
use Symfony\Component\Routing\Route;
5+
use Symfony\Component\Routing\RouteCollection;
6+
7+
return function (string $format) {
8+
$expectedRoutes = new RouteCollection();
9+
$expectedRoutes->add('static.en', $route = new Route('/example'));
10+
$route->setHost('www.example.com');
11+
$route->setRequirement('_locale', 'en');
12+
$route->setDefault('_locale', 'en');
13+
$route->setDefault('_canonical_route', 'static');
14+
$expectedRoutes->add('static.nl', $route = new Route('/example'));
15+
$route->setHost('www.example.nl');
16+
$route->setRequirement('_locale', 'nl');
17+
$route->setDefault('_locale', 'nl');
18+
$route->setDefault('_canonical_route', 'static');
19+
20+
$expectedRoutes->addResource(new FileResource(__DIR__."/route-with-hosts.$format"));
21+
22+
return $expectedRoutes;
23+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Symfony\Component\Routing\Loader\Configurator;
4+
5+
return function (RoutingConfigurator $routes) {
6+
$routes->add('static', '/example')->host([
7+
'nl' => 'www.example.nl',
8+
'en' => 'www.example.com',
9+
]);
10+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
https://symfony.com/schema/routing/routing-1.0.xsd">
6+
<route id="static" path="/example">
7+
<host locale="nl">www.example.nl</host>
8+
<host locale="en">www.example.com</host>
9+
</route>
10+
</routes>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
static:
3+
path: /example
4+
host:
5+
nl: www.example.nl
6+
en: www.example.com

Tests/Loader/PhpFileLoaderTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,16 @@ public function testImportingRoutesWithSingleHostInImporter()
317317
$this->assertEquals($expectedRoutes('php'), $routes);
318318
}
319319

320+
public function testAddingRouteWithHosts()
321+
{
322+
$loader = new PhpFileLoader(new FileLocator([__DIR__.'/../Fixtures/locale_and_host']));
323+
$routes = $loader->load('route-with-hosts.php');
324+
325+
$expectedRoutes = require __DIR__.'/../Fixtures/locale_and_host/route-with-hosts-expected-collection.php';
326+
327+
$this->assertEquals($expectedRoutes('php'), $routes);
328+
}
329+
320330
public function testImportingAliases()
321331
{
322332
$loader = new PhpFileLoader(new FileLocator([__DIR__.'/../Fixtures/alias']));

Tests/Loader/XmlFileLoaderTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,16 @@ public function testImportingRoutesWithSingleHostsInImporter()
587587
$this->assertEquals($expectedRoutes('xml'), $routes);
588588
}
589589

590+
public function testAddingRouteWithHosts()
591+
{
592+
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures/locale_and_host']));
593+
$routes = $loader->load('route-with-hosts.xml');
594+
595+
$expectedRoutes = require __DIR__.'/../Fixtures/locale_and_host/route-with-hosts-expected-collection.php';
596+
597+
$this->assertEquals($expectedRoutes('xml'), $routes);
598+
}
599+
590600
public function testWhenEnv()
591601
{
592602
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures']), 'some-env');

Tests/Loader/YamlFileLoaderTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,16 @@ public function testImportingRoutesWithSingleHostInImporter()
450450
$this->assertEquals($expectedRoutes('yml'), $routes);
451451
}
452452

453+
public function testAddingRouteWithHosts()
454+
{
455+
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures/locale_and_host']));
456+
$routes = $loader->load('route-with-hosts.yml');
457+
458+
$expectedRoutes = require __DIR__.'/../Fixtures/locale_and_host/route-with-hosts-expected-collection.php';
459+
460+
$this->assertEquals($expectedRoutes('yml'), $routes);
461+
}
462+
453463
public function testWhenEnv()
454464
{
455465
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures']), 'some-env');

0 commit comments

Comments
 (0)