Closed
Description
Currently configuring the _scheme
and _method
requirement in routes is pretty strange and also wrong in some cases. Current example:
route_name:
pattern: /hello/{slug}
hostname_pattern: {locale}.example.com
requirements:
locale: en|fr
slug: \w+
_scheme: HTTPS
_method: GET|POST
defaults:
_controller: Foo:bar:baz
The problems are:
- variables in the requirement section reference placeholders. Except for _scheme and _method!
- these requirements allow regular expressions. But this is not true for _scheme and _method because many places of the routing component expect a delimited list like
GET|POST
. So normal regex like.+
does not work for them and breaks code.
My proposal:
route_name:
pattern: /hello/{slug}
hostname_pattern: {locale}.example.com
schemes: HTTPS
methods: [GET, POST]
requirements:
locale: en|fr
slug: \w+
defaults:
_controller: Foo:bar:baz
This makes these scheme and method an option like pattern
which is much more consistent as they are on the "same level" as the path pattern because all of them belong to the HTTP request (method + URL). One can also clearly define that not any regex is valid but only a single string or an array of allowed methods.