Skip to content
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

Automatically load routes in app controllers #6513

Merged
merged 2 commits into from Nov 13, 2023

Conversation

aschempp
Copy link
Member

If you have controllers with Symfony routes, you currently need to manually add a routes.yaml to your project to load that folder. This would automatically load controller routes if no routes.yaml exists. Loading both is problematic because they could override each other.

@aschempp aschempp added this to the 5.3 milestone Nov 12, 2023
@aschempp aschempp requested a review from a team November 12, 2023 21:54
@aschempp aschempp self-assigned this Nov 12, 2023
Toflar
Toflar previously approved these changes Nov 12, 2023
Copy link
Contributor

@fritzmg fritzmg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also automatically add the controller.service_arguments tag for src/Controller services, should we not? Otherwise you cannot use DI in your controllers.

bytehead
bytehead previously approved these changes Nov 13, 2023
@aschempp
Copy link
Member Author

We should also automatically add the controller.service_arguments tag for src/Controller services, should we not? Otherwise you cannot use DI in your controllers.

I don't think that's related, that's a configuration of your service. I would usually use #[AsController] which is autoconfigured since we have service autoconfiguration as well.

@fritzmg
Copy link
Contributor

fritzmg commented Nov 13, 2023

that's a configuration of your service.

But the point of this PR is to automatically have route configuration available via annotations available for your controllers in src/Controller without having to define a routes.yaml. Just like the services.php automatically registers all classes in App\ as services for you without having to define a services.yaml.

But yes, you can of course add #[AsController] to every controller where you need DI. But since this is about convenience I thought we should also add this to the service configuration as well.

@aschempp
Copy link
Member Author

I don't see that as the same thing. This is route registration. The other thing is "make this class public and allow action injection". You can use one without the other, and you don't need add config files now in either way.

@aschempp aschempp dismissed stale reviews from bytehead and Toflar via 68efd9e November 13, 2023 12:23
@leofeyer leofeyer merged commit 1954ac6 into contao:5.x Nov 13, 2023
16 checks passed
@leofeyer
Copy link
Member

Thank you @aschempp.

@aschempp aschempp deleted the feature/controller-routes branch November 14, 2023 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants