Description
Symfony version(s) affected
7.0
Description
Hi. I'm using symfony 6.4 and wish to upgrade to 7.0
everything works besides one thing: routing based on host
I have 3 controller namespaces, say src/Controller/{Landing,Api,App}
I have 3 files like config/routes/{landing,api,app}.yaml
and they have a resource: ../../src/Controller/Landing
for example to indicate that this concerns only those controllers
I have in this yaml a name_prefix: landing.
for example.
A controller would have #[Route("/", name="dashboard")]
in src/Controller/Landing
I have also in that yaml file a host array that would contain for example: landing.com,staging.company.com,validation.company.com,landing.localhost]
etc
It works well with symfony 6.
(by the way I have never understood why, but symfony assumed that this was a locale, and that the locale value is the array index in host: 0, 1, and so on)
For example if I go to https://landing.com
then the route is landing.homepage.0
. If I go on my machine on http://landing.localhost/
then the route is landing.homepage.3
Now on symfony 7, it refuses to compile: it says that target route "landing.homepage" for alias "landing.App\Controller\Landing\MainController::homepage" does not exist
However it does, but I think the locale thing based on the array index in the host
setting of the yml configuration messes up the list of routes.
Is it a regression in 7? I didn't see this as deprecated (and it works) on 6.4.
How to reproduce
- Create a default symfony project
- Create 2 folders in the
Controller
namespace, each with aDefaultController.php
file, each with a#[Route("/", name="dashboard")]
insrc/Controller/Landing
annotated function - Create 2 yaml files in
config/routes/
, each with aname_prefix: xxx
(putabc
anddef
, orlanding
andapi
, etc) and each with ahosts
array containing at least 2 entries (for example:api.prod.com,api.localhost
andlanding.prod.com,landing.localhost
) - Configure 2 virtual hosts on your web server so that
api.localhost
andlanding.localhost
both point to 127.0.0.1 with appropriate symfony configuration (e.g. symfony/apache-pack) - Clear cache, or go to
http://landing.localhost
(make sure/etc/hosts
has entries to point to 127.0.0.1, if needed)
The error will appear
Possible Solution
No response
Additional Context
No response