Allow controller service wiring via constructor parameter attributes

Created on 18 October 2023, about 1 year ago
Updated 30 October 2023, about 1 year ago

Problem/Motivation

To wire services to a controller, developers must implement a custom create() method that pulls services from the container and calls the constructor.

Using PHP 8 attributes, we can tag constructor parameters directly and allow the base class to discover and inject the required services, dropping the create() method entirely.

This also has the advantage of placing the service name directly next to the parameter where it is used, instead of having to keep the create() method and constructor signature in sync in two different places.

Steps to reproduce

Proposed resolution

Add support to ControllerBase for Symfony's #[Autowire] attribute.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

📌 Task
Status

Fixed

Version

10.2

Component
Base 

Last updated about 4 hours ago

Created by

🇬🇧United Kingdom longwave UK

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024