feature #35281 [FrameworkBundle] Configure RequestContext through router 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
-------

6658900703 [FrameworkBundle] Configure RequestContext through router config
This commit is contained in:
Fabien Potencier 2020-01-10 09:06:12 +01:00
commit cc64b028b6
4 changed files with 22 additions and 3 deletions

View File

@ -482,6 +482,15 @@ class Configuration implements ConfigurationInterface
->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()

View File

@ -854,6 +854,11 @@ class FrameworkExtension extends Extension
$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)

View File

@ -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>

View File

@ -413,6 +413,11 @@ class ConfigurationTest extends TestCase
'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,