Skip to content

[HttpFoundation][HttpKernel] Rename master request to main request #40536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions UPGRADE-5.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ FrameworkBundle
* Deprecate the `framework.session.storage_id` configuration option, use the `framework.session.storage_factory_id` configuration option instead
* Deprecate the `session` service and the `SessionInterface` alias, use the `\Symfony\Component\HttpFoundation\Request::getSession()` or the new `\Symfony\Component\HttpFoundation\RequestStack::getSession()` methods instead
* Deprecate the `KernelTestCase::$container` property, use `KernelTestCase::getContainer()` instead
* Rename the container parameter `profiler_listener.only_master_requests` to `profiler_listener.only_main_requests`

HttpFoundation
--------------

* Deprecate the `NamespacedAttributeBag` class
* Deprecate the `RequestStack::getMasterRequest()` method and add `getMainRequest()` as replacement

HttpKernel
----------
Expand All @@ -49,6 +51,8 @@ HttpKernel
* Deprecate `ArgumentMetadata::getAttribute()`, use `getAttributes()` instead
* Mark the class `Symfony\Component\HttpKernel\EventListener\DebugHandlersListener` as internal
* Deprecate returning a `ContainerBuilder` from `KernelInterface::registerContainerConfiguration()`
* Deprecate `HttpKernelInterface::MASTER_REQUEST` and add `HttpKernelInterface::MAIN_REQUEST` as replacement
* Deprecate `KernelEvent::isMasterRequest()` and add `isMainRequest()` as replacement

Messenger
---------
Expand Down
3 changes: 3 additions & 0 deletions UPGRADE-6.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ HttpFoundation
`BinaryFileResponse::create()` methods (use `__construct()` instead)
* Not passing a `Closure` together with `FILTER_CALLBACK` to `ParameterBag::filter()` throws an `InvalidArgumentException`; wrap your filter in a closure instead.
* Removed the `Request::HEADER_X_FORWARDED_ALL` constant, use either `Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO` or `Request::HEADER_X_FORWARDED_AWS_ELB` or `Request::HEADER_X_FORWARDED_TRAEFIK`constants instead.
* Rename `RequestStack::getMasterRequest()` to `getMainRequest()`

HttpKernel
----------
Expand All @@ -98,6 +99,8 @@ HttpKernel
* Make `WarmableInterface::warmUp()` return a list of classes or files to preload on PHP 7.4+
* Remove support for `service:action` syntax to reference controllers. Use `serviceOrFqcn::method` instead.
* Remove support for returning a `ContainerBuilder` from `KernelInterface::registerContainerConfiguration()`
* Rename `HttpKernelInterface::MASTER_REQUEST` to `MAIN_REQUEST`
* Rename `KernelEvent::isMasterRequest()` to `isMainRequest()`

Inflector
---------
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Monolog/Handler/ChromePhpHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ChromePhpHandler extends BaseChromePhpHandler
*/
public function onKernelResponse(ResponseEvent $event)
{
if (!$event->isMasterRequest()) {
if (!$event->isMainRequest()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function isHandlerActivated(array $record): bool
$isActivated
&& isset($record['context']['exception'])
&& $record['context']['exception'] instanceof HttpException
&& ($request = $this->requestStack->getMasterRequest())
&& ($request = $this->requestStack->getMainRequest())
) {
foreach ($this->exclusions as $exclusion) {
if ($record['context']['exception']->getStatusCode() !== $exclusion['code']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function isHandlerActivated(array $record): bool
&& isset($record['context']['exception'])
&& $record['context']['exception'] instanceof HttpException
&& 404 == $record['context']['exception']->getStatusCode()
&& ($request = $this->requestStack->getMasterRequest())
&& ($request = $this->requestStack->getMainRequest())
) {
return !preg_match($this->exclude, $request->getPathInfo());
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Monolog/Handler/FirePHPHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class FirePHPHandler extends BaseFirePHPHandler
*/
public function onKernelResponse(ResponseEvent $event)
{
if (!$event->isMasterRequest()) {
if (!$event->isMainRequest()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Monolog/Processor/RouteProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function reset()

public function addRouteData(RequestEvent $event)
{
if ($event->isMasterRequest()) {
if ($event->isMainRequest()) {
$this->reset();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Monolog/Processor/WebProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(array $extraFields = null)

public function onKernelRequest(RequestEvent $event)
{
if ($event->isMasterRequest()) {
if ($event->isMainRequest()) {
$this->serverData = $event->getRequest()->server->all();
$this->serverData['REMOTE_ADDR'] = $event->getRequest()->getClientIp();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ public function testProcessorDoesNothingWhenNoRequest()
$this->assertEquals(['extra' => []], $record);
}

private function getRequestEvent(Request $request, int $requestType = HttpKernelInterface::MASTER_REQUEST): RequestEvent
private function getRequestEvent(Request $request, int $requestType = HttpKernelInterface::MAIN_REQUEST): RequestEvent
{
return new RequestEvent($this->createMock(HttpKernelInterface::class), $request, $requestType);
}

private function getFinishRequestEvent(Request $request): FinishRequestEvent
{
return new FinishRequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST);
return new FinishRequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MAIN_REQUEST);
}

private function mockEmptyRequest(): Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private function createRequestEvent(array $additionalServerParameters = []): arr
$request->server->replace($server);
$request->headers->replace($server);

$event = new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MAIN_REQUEST);

return [$event, $server];
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Monolog/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"php": ">=7.2.5",
"monolog/monolog": "^1.25.1|^2",
"symfony/service-contracts": "^1.1|^2",
"symfony/http-kernel": "^4.4|^5.0",
"symfony/http-kernel": "^5.3",
"symfony/deprecation-contracts": "^2.1"
},
"require-dev": {
Expand All @@ -32,7 +32,7 @@
},
"conflict": {
"symfony/console": "<4.4",
"symfony/http-foundation": "<4.4"
"symfony/http-foundation": "<5.3"
},
"suggest": {
"symfony/http-kernel": "For using the debugging handlers together with the response life cycle of the HTTP kernel.",
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Extension/WebLinkExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function getFunctions(): array
*/
public function link(string $uri, string $rel, array $attributes = []): string
{
if (!$request = $this->requestStack->getMasterRequest()) {
if (!$request = $this->requestStack->getMainRequest()) {
return $uri;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Twig/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"symfony/dependency-injection": "^4.4|^5.0",
"symfony/finder": "^4.4|^5.0",
"symfony/form": "^5.3",
"symfony/http-foundation": "^4.4|^5.0",
"symfony/http-foundation": "^5.3",
"symfony/http-kernel": "^4.4|^5.0",
"symfony/intl": "^4.4|^5.0",
"symfony/mime": "^5.2",
Expand Down Expand Up @@ -57,7 +57,7 @@
"phpdocumentor/type-resolver": "<1.4.0",
"symfony/console": "<4.4",
"symfony/form": "<5.3",
"symfony/http-foundation": "<4.4",
"symfony/http-foundation": "<5.3",
"symfony/http-kernel": "<4.4",
"symfony/translation": "<5.2",
"symfony/workflow": "<5.2"
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ CHANGELOG
* Add support to use a PSR-6 compatible cache for Doctrine annotations
* Deprecate all other values than "none", "php_array" and "file" for `framework.annotation.cache`
* Add `KernelTestCase::getContainer()` as the best way to get a container in tests
* Rename the container parameter `profiler_listener.only_master_requests` to `profiler_listener.only_main_requests`

5.2.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ private function addProfilerSection(ArrayNodeDefinition $rootNode)
->children()
->booleanNode('collect')->defaultTrue()->end()
->booleanNode('only_exceptions')->defaultFalse()->end()
->booleanNode('only_master_requests')->defaultFalse()->end()
->booleanNode('only_main_requests')->defaultFalse()->end()
->booleanNode('only_master_requests')->setDeprecated('symfony/framework-bundle', '5.3', 'Option "%node%" at "%path%" is deprecated, use "only_main_requests" instead.')->defaultFalse()->end()
->scalarNode('dsn')->defaultValue('file:%kernel.cache_dir%/profiler')->end()
->end()
->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ private function registerProfilerConfiguration(array $config, ContainerBuilder $
}

$container->setParameter('profiler_listener.only_exceptions', $config['only_exceptions']);
$container->setParameter('profiler_listener.only_master_requests', $config['only_master_requests']);
$container->setParameter('profiler_listener.only_main_requests', $config['only_main_requests'] || $config['only_master_requests']);

// Choose storage class based on the DSN
[$class] = explode(':', $config['dsn'], 2);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/HttpCache/HttpCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct(KernelInterface $kernel, $cache = null, SurrogateInt
parent::__construct($kernel, $this->createStore(), $this->createSurrogate(), array_merge($this->options, $this->getOptions()));
}

public function handle(Request $request, int $type = HttpKernelInterface::MASTER_REQUEST, bool $catch = true)
public function handle(Request $request, int $type = HttpKernelInterface::MAIN_REQUEST, bool $catch = true)
{
if ($this->kernel->getContainer()->getParameter('kernel.http_method_override')) {
Request::enableHttpMethodParameterOverride();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
service('request_stack'),
null,
param('profiler_listener.only_exceptions'),
param('profiler_listener.only_master_requests'),
param('profiler_listener.only_main_requests'),
])
->tag('kernel.event_subscriber')
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<xsd:complexType name="profiler">
<xsd:attribute name="collect" type="xsd:string" />
<xsd:attribute name="only-exceptions" type="xsd:string" />
<xsd:attribute name="only-main-requests" type="xsd:string" />
<xsd:attribute name="only-master-requests" type="xsd:string" />
<xsd:attribute name="enabled" type="xsd:string" />
<xsd:attribute name="dsn" type="xsd:string" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ protected static function getBundleDefaultConfig()
'enabled' => false,
'only_exceptions' => false,
'only_master_requests' => false,
'only_main_requests' => false,
'dsn' => 'file:%kernel.cache_dir%/profiler',
'collect' => true,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ protected function configureRoutes(RoutingConfigurator $routes): void
};

$request = Request::create('/');
$response = $kernel->handle($request, HttpKernelInterface::MASTER_REQUEST, false);
$response = $kernel->handle($request, HttpKernelInterface::MAIN_REQUEST, false);

$this->assertSame('Hello World!', $response->getContent());
}
Expand Down Expand Up @@ -156,7 +156,7 @@ protected function configureContainer(ContainerConfigurator $c): void
$this->expectExceptionMessage('"Symfony\Bundle\FrameworkBundle\Tests\Kernel\MinimalKernel@anonymous" uses "Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait", but does not implement the required method "protected function configureRoutes(RoutingConfigurator $routes): void".');

$request = Request::create('/');
$kernel->handle($request, HttpKernelInterface::MASTER_REQUEST, false);
$kernel->handle($request, HttpKernelInterface::MAIN_REQUEST, false);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"symfony/event-dispatcher": "^5.1",
"symfony/error-handler": "^4.4.1|^5.0.1",
"symfony/http-foundation": "^5.3",
"symfony/http-kernel": "^5.2.1",
"symfony/http-kernel": "^5.3",
"symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php80": "^1.15",
"symfony/filesystem": "^4.4|^5.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(FirewallMapInterface $map, EventDispatcherInterface

public function configureLogoutUrlGenerator(RequestEvent $event)
{
if (!$event->isMasterRequest()) {
if (!$event->isMainRequest()) {
return;
}

Expand All @@ -49,7 +49,7 @@ public function configureLogoutUrlGenerator(RequestEvent $event)

public function onKernelFinishRequest(FinishRequestEvent $event)
{
if ($event->isMasterRequest()) {
if ($event->isMainRequest()) {
$this->logoutUrlGenerator->setCurrentFirewall(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function authenticateUser(UserInterface $user, AuthenticatorInterface $au

private function getUserAuthenticator(): UserAuthenticatorInterface
{
$firewallConfig = $this->firewallMap->getFirewallConfig($this->requestStack->getMasterRequest());
$firewallConfig = $this->firewallMap->getFirewallConfig($this->requestStack->getMainRequest());
if (null === $firewallConfig) {
throw new LogicException('Cannot call authenticate on this request, as it is not behind a firewall.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public function testGetFirewallReturnsNull()
public function testGetListeners()
{
$request = new Request();
$event = new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MAIN_REQUEST);
$event->setResponse($response = new Response());
$listener = function ($e) use ($event, &$listenerCalled) {
$listenerCalled += $e === $event;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TraceableFirewallListenerTest extends TestCase
public function testOnKernelRequestRecordsListeners()
{
$request = new Request();
$event = new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MAIN_REQUEST);
$event->setResponse($response = new Response());
$listener = function ($e) use ($event, &$listenerCalled) {
$listenerCalled += $e === $event;
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Bundle/SecurityBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"symfony/dependency-injection": "^5.3",
"symfony/deprecation-contracts": "^2.1",
"symfony/event-dispatcher": "^5.1",
"symfony/http-kernel": "^5.0",
"symfony/http-kernel": "^5.3",
"symfony/http-foundation": "^5.3",
"symfony/password-hasher": "^5.3",
"symfony/polyfill-php80": "^1.15",
"symfony/security-core": "^5.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function onKernelResponse(ResponseEvent $event)
}
}

if (!$event->isMasterRequest()) {
if (!$event->isMainRequest()) {
return;
}

Expand Down
Loading