Skip to content

[DI][HttpKernel] Make bind also apply to controller arguments #25960

@weaverryan

Description

@weaverryan
Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? yes-ish
Symfony version 4.1

Hi guys!

  1. controller "action-injection" is a shortcut we added for convenience.
  2. action-injection works like constructor or method injection for services, but it does not work the same with bind: bind applies to the constructor & methods, but it does NOT work for actions.

For example:

services:
    _defaults:
        bind:
            $isDebug: '%kernel.debug%'
/**
 * @Route("/foo/bar")
 */
public function foo($isDebug)
{
}

This will fail. I'd like this to work - because it would make action-injection consistent with other injection. And I think it shouldn't be too difficult: (A) take the binding rules that apply to the controller service, (B) use those to create a map (similar to what we do for the service injection) of controller+argname => value and (C) create another argument (with low priority) that will fill in the argument.

Does anyone see any issues? I'm creating in the hope that someone will take it on :). I can... eventually... would really like to have this.

Cheers!

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