Skip to content

Arrays in route parameters' requirements #47971

Closed
@Thibibi

Description

@Thibibi

Description

Hi guys,

I'd like to set a requirement on a parameter of my routes, this notation works fine:

#[Route('/{_locale}/teacher/create', name: 'app_teacher_create', requirements: ['_locale' => 'fr|en'])]
public function createTeacher(blah blah blah): Response

As I have to write that requirement in dozens of routes, and later I'll probably want to change the list, I prefer to set it in a configuration file:

# Config/Services.yaml
parameters:
    app.supported_locales: ['en', 'es', 'fr']

Then my controller is modified:

#[Route('/{_locale}/teacher/create', name: 'app_teacher_create', requirements: ['_locale' => '%app.supported_locales%'])]
public function createTeacher(blah blah blah): Response

But unfortunately:

RuntimeException: The container parameter "app.supported_locales", used in the route configuration value "%app.supported_locales%", must be a string or numeric, but it is of type "array".

Well, I could do:

# Config/Services.yaml
parameters:
    app.supported_locales: 'en|es|fr'

But this is kinda strange, in some other place I might prefer to have the array in config file, so that I can browse it item by item.

Support of arrays in route parameters' requirement would seem nice don't you think?

Example

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