-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Closed
Copy link
Labels
BugHelp wantedIssues and PRs which are looking for volunteers to complete them.Issues and PRs which are looking for volunteers to complete them.RoutingStatus: Needs Review
Description
Symfony version(s) affected: 3.2 - master
Description
Using env vars in routing configuration is not supported and actively denied:
symfony/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php
Lines 163 to 165 in e3927b6
if (preg_match('/^env\(\w+\)$/', $match[1])) { | |
throw new RuntimeException(sprintf('Using "%%%s%%" is not allowed in routing configuration.', $match[1])); | |
} |
However, if we use indirection with a parameter we can avoid this error, but routing will not work as expected.
How to reproduce
This will be denied correctly, as described above:
# config.yaml
parameters:
env(route_prefix): 'default'
# routes.yaml
some_route:
path: /%env(route_prefix)%/contact
controller: App\Controller\MainController::contact
However, this will not throw an error:
# config.yaml
parameters:
env(route_prefix): 'default'
route_prefix: '%env(route_prefix)%'
# routes.yaml
some_route:
path: /%route_prefix%/contact
controller: App\Controller\MainController::contact
This will allow the container to boot, but defining a different route_prefix
env var will never have any effect.
Possible Solution
For good and non confusing DX, detect if parameters are pointing to env vars and deny building routes up front.
Metadata
Metadata
Assignees
Labels
BugHelp wantedIssues and PRs which are looking for volunteers to complete them.Issues and PRs which are looking for volunteers to complete them.RoutingStatus: Needs Review