Skip to content

Routing by host with name prefix not working in 7.0 (works in 6.4) #52956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
BenoitDuffez opened this issue Dec 8, 2023 · 3 comments
Closed

Comments

@BenoitDuffez
Copy link

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

@BenoitDuffez
Copy link
Author

Well, this is awkward. I took the reproduction steps and did it, and I don't reproduce. Please don't waste time (yet), I have some homework to do

https://github.com/BenoitDuffez/symfony_52956

@BenoitDuffez
Copy link
Author

I stripped a lot of code of my app to match the sample linked above, but it still fails. I'll continue.

Meanwhile, I think it could be related to this: https://symfony.com/blog/new-in-symfony-6-4-fqcn-based-routes

@BenoitDuffez
Copy link
Author

I noticed in composer.lock that symfony/routing was 7.0.1 while my app was in 7.0.0. There is a difference here:

I forced the update to 7.0.1 which yielded:


  - Upgrading symfony/http-kernel (v7.0.0 => v7.0.1): Extracting archive
  - Upgrading symfony/dependency-injection (v7.0.0 => v7.0.1): Extracting archive
  - Upgrading symfony/routing (v7.0.0 => v7.0.1): Extracting archive
  - Upgrading symfony/framework-bundle (v7.0.0 => v7.0.1): Extracting archive
  - Upgrading symfony/form (v7.0.0 => v7.0.1): Extracting archive

And now the problem is fixed. I guess it was a bug in symfony/routing 7.0.0, fixed in 7.0.1.

Perhaps related to #52805

@xabbuh xabbuh added the Routing label Dec 9, 2023
@xabbuh xabbuh closed this as not planned Won't fix, can't repro, duplicate, stale Dec 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants