Skip to content
Permalink
Browse files

feature #35281 [FrameworkBundle] Configure RequestContext through rou…

…ter config (benji07)

This PR was merged into the 5.1-dev branch.

Discussion
----------

[FrameworkBundle] Configure RequestContext through router config

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Fix #35229  <!-- prefix each issue number with "Fix #", if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->
<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.

Additionally (see https://symfony.com/roadmap):
 - Always add tests and ensure they pass.
 - Never break backward compatibility (see https://symfony.com/bc).
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too.)
 - Features and deprecations must be submitted against branch master.
-->

- [ ] PR on symfony/symfony-docs

Commits
-------

6658900 [FrameworkBundle] Configure RequestContext through router config
  • Loading branch information
fabpot committed Jan 10, 2020
2 parents 5c37ab0 + 6658900 commit cc64b028b67e490d38e7b35c4353c0635ea565c2
@@ -482,6 +482,15 @@ private function addRouterSection(ArrayNodeDefinition $rootNode)
->defaultTrue()
->end()
->booleanNode('utf8')->defaultFalse()->end()
->arrayNode('context')
->info('router request context')
->addDefaultsIfNotSet()
->children()
->scalarNode('host')->defaultValue('%router.request_context.host%')->end()
->scalarNode('scheme')->defaultValue('%router.request_context.scheme%')->end()
->scalarNode('base_url')->defaultValue('%router.request_context.base_url%')->end()
->end()
->end()
->end()
->end()
->end()
@@ -854,6 +854,11 @@ private function registerRouterConfiguration(array $config, ContainerBuilder $co
$container->setParameter('request_listener.http_port', $config['http_port']);
$container->setParameter('request_listener.https_port', $config['https_port']);

$requestContext = $container->findDefinition('router.request_context');
$requestContext->replaceArgument(0, $config['context']['base_url']);
$requestContext->replaceArgument(2, $config['context']['host']);
$requestContext->replaceArgument(3, $config['context']['scheme']);

if ($this->annotationsConfigEnabled) {
$container->register('routing.loader.annotation', AnnotatedRouteControllerLoader::class)
->setPublic(false)
@@ -79,10 +79,10 @@
<service id="Symfony\Component\Routing\RequestContextAwareInterface" alias="router" />

<service id="router.request_context" class="Symfony\Component\Routing\RequestContext">
<argument>%router.request_context.base_url%</argument>
<argument></argument> <!-- base_url -->
<argument>GET</argument>
<argument>%router.request_context.host%</argument>
<argument>%router.request_context.scheme%</argument>
<argument></argument> <!-- host -->
<argument></argument> <!-- scheme -->
<argument>%request_listener.http_port%</argument>
<argument>%request_listener.https_port%</argument>
</service>
@@ -413,6 +413,11 @@ protected static function getBundleDefaultConfig()
'https_port' => 443,
'strict_requirements' => true,
'utf8' => false,
'context' => [
'host' => '%router.request_context.host%',
'scheme' => '%router.request_context.scheme%',
'base_url' => '%router.request_context.base_url%',
],
],
'session' => [
'enabled' => false,

0 comments on commit cc64b02

Please sign in to comment.
You can’t perform that action at this time.