diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index a175e04b9486563b10da8f5379794ee0171c7252..04ce6ca97b03df9e72f6eefac9e43177edb99a70 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -690,7 +690,7 @@ public function terminate(Request $request, Response $response) { /** * {@inheritdoc} */ - public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) { + public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE): Response { // Ensure sane PHP environment variables. static::bootEnvironment(); diff --git a/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php b/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php index 6d469e2507e92c605baefc1a8d8478e651dfb005..5df27acc714289df757db826449b8fcb3ba0e36e 100644 --- a/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php +++ b/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php @@ -4,6 +4,7 @@ use Drupal\Core\DrupalKernelInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpKernelInterface; /** @@ -41,7 +42,7 @@ public function __construct(HttpKernelInterface $http_kernel, DrupalKernelInterf /** * {@inheritdoc} */ - public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) { + public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE): Response { $this->drupalKernel->preHandle($request); return $this->httpKernel->handle($request, $type, $catch); diff --git a/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php b/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php index f3b30e29a3df40efc78706c104c2d18a65e96e64..ecc6dd61ea1c34f7b4ff5393a622e90aca3edf87 100644 --- a/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php +++ b/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php @@ -3,6 +3,7 @@ namespace Drupal\Core\StackMiddleware; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpKernelInterface; /** @@ -37,7 +38,7 @@ public function __construct(HttpKernelInterface $app) { /** * {@inheritdoc} */ - public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) { + public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE): Response { // Register available mime types. foreach ($this->formats as $format => $mime_type) { $request->setFormat($format, $mime_type); diff --git a/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php b/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php index 647f44bbbc4c072f5bde6c32f400226f4049edcb..69221e7989192bc54932a505e5f142eb5e2eddf5 100644 --- a/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php +++ b/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php @@ -4,6 +4,7 @@ use Drupal\Core\Site\Settings; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpKernelInterface; /** @@ -41,7 +42,7 @@ public function __construct(HttpKernelInterface $http_kernel, Settings $settings /** * {@inheritdoc} */ - public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) { + public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE): Response { // Initialize proxy settings. static::setSettingsOnRequest($request, $this->settings); return $this->httpKernel->handle($request, $type, $catch); diff --git a/core/lib/Drupal/Core/StackMiddleware/Session.php b/core/lib/Drupal/Core/StackMiddleware/Session.php index d520916d26ac8ef902cfa59f0a1d508d67c153c4..8c3eb5d74f0fe3f04a10412ca7b7b5c4be539106 100644 --- a/core/lib/Drupal/Core/StackMiddleware/Session.php +++ b/core/lib/Drupal/Core/StackMiddleware/Session.php @@ -4,6 +4,7 @@ use Symfony\Component\DependencyInjection\ContainerAwareTrait; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpKernelInterface; /** @@ -47,7 +48,7 @@ public function __construct(HttpKernelInterface $http_kernel, $service_name = 's /** * {@inheritdoc} */ - public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) { + public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE): Response { if ($type === self::MASTER_REQUEST && PHP_SAPI !== 'cli') { $session = $this->container->get($this->sessionServiceName); $session->start(); diff --git a/core/lib/Drupal/Core/Update/UpdateKernel.php b/core/lib/Drupal/Core/Update/UpdateKernel.php index edcee199607b321490da31810bfe70c83231bb4f..4a781ff477d2c1da6813d6356202749e2ceda8b8 100644 --- a/core/lib/Drupal/Core/Update/UpdateKernel.php +++ b/core/lib/Drupal/Core/Update/UpdateKernel.php @@ -9,6 +9,7 @@ use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; /** @@ -54,7 +55,7 @@ protected function cacheDrupalContainer(array $container_definition) { /** * {@inheritdoc} */ - public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) { + public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE): Response { try { static::bootEnvironment(); diff --git a/core/modules/ban/src/BanMiddleware.php b/core/modules/ban/src/BanMiddleware.php index eda1fa0eb4185a49d470e91e5bc233ed9127f902..dc5b8d4dae00432a61f4f4940a52c025bf92f615 100644 --- a/core/modules/ban/src/BanMiddleware.php +++ b/core/modules/ban/src/BanMiddleware.php @@ -42,7 +42,7 @@ public function __construct(HttpKernelInterface $http_kernel, BanIpManagerInterf /** * {@inheritdoc} */ - public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) { + public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE): Response { $ip = $request->getClientIp(); if ($this->banIpManager->isBanned($ip)) { return new Response(new FormattableMarkup('@ip has been banned', ['@ip' => $ip]), 403); diff --git a/core/modules/page_cache/src/StackMiddleware/PageCache.php b/core/modules/page_cache/src/StackMiddleware/PageCache.php index ba07414d63ea581e009ba631323ce9e5380ed807..2c425657fbcf9d49c8c04a5d685a8cc610933abc 100644 --- a/core/modules/page_cache/src/StackMiddleware/PageCache.php +++ b/core/modules/page_cache/src/StackMiddleware/PageCache.php @@ -76,7 +76,7 @@ public function __construct(HttpKernelInterface $http_kernel, CacheBackendInterf /** * {@inheritdoc} */ - public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) { + public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE): Response { // Only allow page caching on master request. if ($type === static::MASTER_REQUEST && $this->requestPolicy->check($request) === RequestPolicyInterface::ALLOW) { $response = $this->lookup($request, $type, $catch); diff --git a/core/modules/system/tests/modules/accept_header_routing_test/src/AcceptHeaderMiddleware.php b/core/modules/system/tests/modules/accept_header_routing_test/src/AcceptHeaderMiddleware.php index f607a895accce21e17142d453677e200b594534d..45f2bb7c581315c016fb53bcc4c921b055ea7f17 100644 --- a/core/modules/system/tests/modules/accept_header_routing_test/src/AcceptHeaderMiddleware.php +++ b/core/modules/system/tests/modules/accept_header_routing_test/src/AcceptHeaderMiddleware.php @@ -3,6 +3,7 @@ namespace Drupal\accept_header_routing_test; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpKernelInterface; /** @@ -23,7 +24,7 @@ public function __construct(HttpKernelInterface $app) { /** * {@inheritdoc} */ - public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) { + public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE): Response { $mapping = [ 'application/json' => 'json', 'application/hal+json' => 'hal_json', diff --git a/core/modules/system/tests/modules/error_service_test/src/MonkeysInTheControlRoom.php b/core/modules/system/tests/modules/error_service_test/src/MonkeysInTheControlRoom.php index 4595a055926686bdcc70839415bb4d0e395542f6..304d8ed93b6e597f79966312d899e515b65a718f 100644 --- a/core/modules/system/tests/modules/error_service_test/src/MonkeysInTheControlRoom.php +++ b/core/modules/system/tests/modules/error_service_test/src/MonkeysInTheControlRoom.php @@ -4,6 +4,7 @@ use Drupal\Core\Site\Settings; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpKernelInterface; /** @@ -36,7 +37,7 @@ public function __construct(HttpKernelInterface $app, Settings $settings) { /** * {@inheritdoc} */ - public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) { + public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE): Response { if (\Drupal::state()->get('error_service_test.break_bare_html_renderer')) { // Let the bedlam begin. // 1) Force a container rebuild. diff --git a/core/modules/system/tests/modules/form_test/src/StackMiddleware/FormTestMiddleware.php b/core/modules/system/tests/modules/form_test/src/StackMiddleware/FormTestMiddleware.php index 6afaea9e6e3b98182902fbaa7c2ad7578002e3c2..3db45b9c400ceadedfee7e414f87b45f4fa93110 100644 --- a/core/modules/system/tests/modules/form_test/src/StackMiddleware/FormTestMiddleware.php +++ b/core/modules/system/tests/modules/form_test/src/StackMiddleware/FormTestMiddleware.php @@ -3,6 +3,7 @@ namespace Drupal\form_test\StackMiddleware; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpKernelInterface; /** @@ -30,7 +31,7 @@ public function __construct(HttpKernelInterface $http_kernel) { /** * {@inheritdoc} */ - public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) { + public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE): Response { $response = $this->httpKernel->handle($request, $type, $catch); $response->headers->set('X-Form-Test-Stack-Middleware', 'invoked'); return $response; diff --git a/core/modules/system/tests/modules/httpkernel_test/src/HttpKernel/TestMiddleware.php b/core/modules/system/tests/modules/httpkernel_test/src/HttpKernel/TestMiddleware.php index f9e9849ef360e95fcc3a4136ceded0b6deab7aa8..5bf54c3d9d471969beb29735ca79a8cdd9d28dd8 100644 --- a/core/modules/system/tests/modules/httpkernel_test/src/HttpKernel/TestMiddleware.php +++ b/core/modules/system/tests/modules/httpkernel_test/src/HttpKernel/TestMiddleware.php @@ -3,6 +3,7 @@ namespace Drupal\httpkernel_test\HttpKernel; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpKernelInterface; /** @@ -40,7 +41,7 @@ public function __construct(HttpKernelInterface $kernel, $optional_argument = NU /** * {@inheritdoc} */ - public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) { + public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE): Response { $request->attributes->set('_hello', 'world'); if ($request->attributes->has('_optional_argument')) { $request->attributes->set('_previous_optional_argument', $request->attributes->get('_optional_argument')); diff --git a/core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php b/core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php index 117190960dab248e01aee47b99195d9a9ed35d80..21b02065b22b2b8be50ab4fbfacdec1616efc065 100644 --- a/core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php +++ b/core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php @@ -265,7 +265,7 @@ public function testLoggerException() { $this->assertStringContainsString('Failed to log error', $errors[0], 'The error handling logs when an error could not be logged to the logger.'); $expected_path = \Drupal::root() . '/core/modules/system/tests/modules/error_service_test/src/MonkeysInTheControlRoom.php'; - $expected_line = 61; + $expected_line = 62; $expected_entry = "Failed to log error: Exception: Deforestation in Drupal\\error_service_test\\MonkeysInTheControlRoom->handle() (line ${expected_line} of ${expected_path})"; $this->assertStringContainsString($expected_entry, $errors[0], 'Original error logged to the PHP error log when an exception is thrown by a logger'); diff --git a/core/tests/Drupal/Tests/Core/StackMiddleware/NegotiationMiddlewareTest.php b/core/tests/Drupal/Tests/Core/StackMiddleware/NegotiationMiddlewareTest.php index 6752ee145bcd1c99476e0bfffe5d363573a797e2..bd1137de849520add6bb901e3fa3e700a76c6077 100644 --- a/core/tests/Drupal/Tests/Core/StackMiddleware/NegotiationMiddlewareTest.php +++ b/core/tests/Drupal/Tests/Core/StackMiddleware/NegotiationMiddlewareTest.php @@ -11,6 +11,7 @@ use Drupal\Tests\UnitTestCase; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpKernelInterface; /** @@ -35,7 +36,7 @@ class NegotiationMiddlewareTest extends UnitTestCase { protected function setUp(): void { parent::setUp(); - $this->app = $this->prophesize(HttpKernelInterface::class); + $this->app = $this->prophesize(MockedHttpKernelInterface::class); $this->contentNegotiation = new StubNegotiationMiddleware($this->app->reveal()); } @@ -121,6 +122,13 @@ public function testHandle() { * @covers ::registerFormat */ public function testSetFormat() { + $app = $this->createMock(MockedHttpKernelInterface::class); + $app->expects($this->once()) + ->method('handle') + ->will($this->returnValue($this->createMock(Response::class))); + + $content_negotiation = new StubNegotiationMiddleware($app); + $request = $this->prophesize(Request::class); // Default empty format list should not set any formats. @@ -135,8 +143,8 @@ public function testSetFormat() { $request_mock->request = $request_data->reveal(); // Trigger handle. - $this->contentNegotiation->registerFormat('david', 'geeky/david'); - $this->contentNegotiation->handle($request_mock); + $content_negotiation->registerFormat('david', 'geeky/david'); + $content_negotiation->handle($request_mock); } } @@ -148,3 +156,14 @@ public function getContentType(Request $request) { } } + +/** + * Helper interface for the Symfony 6 version of the HttpKernelInterface. + * + * @todo Remove this interface when the Symfony 6 is in core. + */ +interface MockedHttpKernelInterface extends HttpKernelInterface { + + public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = TRUE): Response; + +} diff --git a/core/tests/Drupal/Tests/Core/StackMiddleware/ReverseProxyMiddlewareTest.php b/core/tests/Drupal/Tests/Core/StackMiddleware/ReverseProxyMiddlewareTest.php index 01f220fef7f7d715e8ce57b20d377c6b0c67e6f8..9823175f7112ab768240d419fe697bbf8cc356de 100644 --- a/core/tests/Drupal/Tests/Core/StackMiddleware/ReverseProxyMiddlewareTest.php +++ b/core/tests/Drupal/Tests/Core/StackMiddleware/ReverseProxyMiddlewareTest.php @@ -6,6 +6,8 @@ use Drupal\Core\StackMiddleware\ReverseProxyMiddleware; use Drupal\Tests\UnitTestCase; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\HttpKernelInterface; /** * Unit test the reverse proxy stack middleware. @@ -23,7 +25,7 @@ class ReverseProxyMiddlewareTest extends UnitTestCase { * {@inheritdoc} */ protected function setUp(): void { - $this->mockHttpKernel = $this->createMock('Symfony\Component\HttpKernel\HttpKernelInterface'); + $this->mockHttpKernel = $this->createMock(MockHttpKernelInterface::class); } /** @@ -104,3 +106,14 @@ protected function trustedHeadersAreSet(Settings $settings, $expected_trusted_he } } + +/** + * Helper interface for the Symfony 6 version of the HttpKernelInterface. + * + * @todo Remove this interface when the Symfony 6 is in core. + */ +interface MockHttpKernelInterface extends HttpKernelInterface { + + public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = TRUE): Response; + +}