8000 Routing by host with name prefix not working in 7.0 (works in 6.4) · Issue #52956 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Routing by host with name prefix not working in 7.0 (works in 6.4) #52956
Closed as not planned
@BenoitDuffez

Description

@BenoitDuffez

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

  1. Create a default symfony project
  2. Create 2 folders in the Controller namespace, each with a DefaultController.php file, each with a #[Route("/", name="dashboard")] in src/Controller/Landing annotated function
  3. Create 2 yaml files in config/routes/, each with a name_prefix: xxx (put abc and def, or landing and api, etc) and each with a hosts array containing at least 2 entries (for example: api.prod.com,api.localhost and landing.prod.com,landing.localhost)
  4. Configure 2 virtual hosts on your web server so that api.localhost and landing.localhost both point to 127.0.0.1 with appropriate symfony configuration (e.g. symfony/apache-pack)
  5. 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0