From 3eb8a344608c59b32747bc4a4e3444e7f76a3cfa Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Wed, 22 Dec 2021 11:15:36 +0000
Subject: [PATCH] Issue #3233031 by daffie, longwave, murilohp: [Symfony 6] Add
 "RequestContext" type hint to methods overridding
 Symfony\Component\Routing\RequestContextAwareInterface::getContext()

---
 .../Render/MetadataBubblingUrlGenerator.php   |  2 +-
 .../Drupal/Core/Routing/AccessAwareRouter.php | 26 ++++++-------------
 .../lib/Drupal/Core/Routing/NullGenerator.php | 13 ----------
 core/lib/Drupal/Core/Routing/UrlGenerator.php |  2 +-
 .../help_test/src/SupernovaGenerator.php      |  2 +-
 5 files changed, 11 insertions(+), 34 deletions(-)

diff --git a/core/lib/Drupal/Core/Render/MetadataBubblingUrlGenerator.php b/core/lib/Drupal/Core/Render/MetadataBubblingUrlGenerator.php
index 82c71377a77d..bbdeaab0a1e6 100644
--- a/core/lib/Drupal/Core/Render/MetadataBubblingUrlGenerator.php
+++ b/core/lib/Drupal/Core/Render/MetadataBubblingUrlGenerator.php
@@ -57,7 +57,7 @@ public function setContext(SymfonyRequestContext $context) {
   /**
    * {@inheritdoc}
    */
-  public function getContext() {
+  public function getContext(): SymfonyRequestContext {
     return $this->urlGenerator->getContext();
   }
 
diff --git a/core/lib/Drupal/Core/Routing/AccessAwareRouter.php b/core/lib/Drupal/Core/Routing/AccessAwareRouter.php
index b13006ca3f05..0e18492567d4 100644
--- a/core/lib/Drupal/Core/Routing/AccessAwareRouter.php
+++ b/core/lib/Drupal/Core/Routing/AccessAwareRouter.php
@@ -9,10 +9,8 @@
 use Drupal\Core\Session\AccountInterface;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
-use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
 use Symfony\Component\Routing\RouteCollection;
 use Symfony\Component\Routing\RequestContext as SymfonyRequestContext;
-use Symfony\Component\Routing\RequestContextAwareInterface;
 use Symfony\Component\Routing\RouterInterface;
 
 /**
@@ -23,7 +21,7 @@ class AccessAwareRouter implements AccessAwareRouterInterface {
   /**
    * The router doing the actual routing.
    *
-   * @var \Symfony\Component\Routing\Matcher\RequestMatcherInterface
+   * @var \Symfony\Component\Routing\RouterInterface
    */
   protected $router;
 
@@ -44,14 +42,14 @@ class AccessAwareRouter implements AccessAwareRouterInterface {
   /**
    * Constructs a router for Drupal with access check and upcasting.
    *
-   * @param \Symfony\Component\Routing\Matcher\RequestMatcherInterface $router
+   * @param \Symfony\Component\Routing\RouterInterface $router
    *   The router doing the actual routing.
    * @param \Drupal\Core\Access\AccessManagerInterface $access_manager
    *   The access manager.
    * @param \Drupal\Core\Session\AccountInterface $account
    *   The account to use in access checks.
    */
-  public function __construct(RequestMatcherInterface $router, AccessManagerInterface $access_manager, AccountInterface $account) {
+  public function __construct(RouterInterface $router, AccessManagerInterface $access_manager, AccountInterface $account) {
     $this->router = $router;
     $this->accessManager = $access_manager;
     $this->account = $account;
@@ -69,18 +67,14 @@ public function __call($name, $arguments) {
    * {@inheritdoc}
    */
   public function setContext(SymfonyRequestContext $context) {
-    if ($this->router instanceof RequestContextAwareInterface) {
-      $this->router->setContext($context);
-    }
+    $this->router->setContext($context);
   }
 
   /**
    * {@inheritdoc}
    */
-  public function getContext() {
-    if ($this->router instanceof RequestContextAwareInterface) {
-      return $this->router->getContext();
-    }
+  public function getContext(): SymfonyRequestContext {
+    return $this->router->getContext();
   }
 
   /**
@@ -127,18 +121,14 @@ protected function checkAccess(Request $request) {
    * {@inheritdoc}
    */
   public function getRouteCollection(): RouteCollection {
-    if ($this->router instanceof RouterInterface) {
-      return $this->router->getRouteCollection();
-    }
+    return $this->router->getRouteCollection();
   }
 
   /**
    * {@inheritdoc}
    */
   public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH): string {
-    if ($this->router instanceof UrlGeneratorInterface) {
-      return $this->router->generate($name, $parameters, $referenceType);
-    }
+    return $this->router->generate($name, $parameters, $referenceType);
   }
 
   /**
diff --git a/core/lib/Drupal/Core/Routing/NullGenerator.php b/core/lib/Drupal/Core/Routing/NullGenerator.php
index 630e81ffe26b..0f0d13ec3bf7 100644
--- a/core/lib/Drupal/Core/Routing/NullGenerator.php
+++ b/core/lib/Drupal/Core/Routing/NullGenerator.php
@@ -4,7 +4,6 @@
 
 use Drupal\Core\Render\BubbleableMetadata;
 use Symfony\Component\HttpFoundation\RequestStack;
-use Symfony\Component\Routing\RequestContext as SymfonyRequestContext;
 use Symfony\Component\Routing\Exception\RouteNotFoundException;
 use Symfony\Component\Routing\Route;
 
@@ -56,18 +55,6 @@ protected function getInternalPathFromRoute($name, Route $route, $parameters = [
     return $route->getPath();
   }
 
-  /**
-   * {@inheritdoc}
-   */
-  public function setContext(SymfonyRequestContext $context) {
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function getContext() {
-  }
-
   /**
    * {@inheritdoc}
    */
diff --git a/core/lib/Drupal/Core/Routing/UrlGenerator.php b/core/lib/Drupal/Core/Routing/UrlGenerator.php
index f56736ab267c..185784db374d 100644
--- a/core/lib/Drupal/Core/Routing/UrlGenerator.php
+++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php
@@ -104,7 +104,7 @@ public function setContext(SymfonyRequestContext $context) {
   /**
    * {@inheritdoc}
    */
-  public function getContext() {
+  public function getContext(): SymfonyRequestContext {
     return $this->context;
   }
 
diff --git a/core/modules/help/tests/modules/help_test/src/SupernovaGenerator.php b/core/modules/help/tests/modules/help_test/src/SupernovaGenerator.php
index 9cdaa41858fb..bfdc97e453a5 100644
--- a/core/modules/help/tests/modules/help_test/src/SupernovaGenerator.php
+++ b/core/modules/help/tests/modules/help_test/src/SupernovaGenerator.php
@@ -20,7 +20,7 @@ public function setContext(RequestContext $context) {
   /**
    * {@inheritdoc}
    */
-  public function getContext() {
+  public function getContext(): RequestContext {
     throw new \Exception();
   }
 
-- 
GitLab