From a0548804635048475c29e688a8f1424e67c3071a Mon Sep 17 00:00:00 2001
From: Dave Long <dave@longwaveconsulting.com>
Date: Fri, 12 Jan 2024 11:11:53 +0000
Subject: [PATCH] Issue #2507237 by dimitriskr, twistor, longwave, smustgrave:
 Replace ReflectionClass::implementsInterface() with is_subclass_of()

---
 .../Compiler/RegisterEventSubscribersPass.php               | 6 +++---
 core/modules/language/src/ConfigurableLanguageManager.php   | 4 +---
 .../language/src/HttpKernel/PathProcessorLanguage.php       | 5 ++---
 3 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterEventSubscribersPass.php b/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterEventSubscribersPass.php
index c2c28b38e774..0cae61c39f77 100644
--- a/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterEventSubscribersPass.php
+++ b/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterEventSubscribersPass.php
@@ -4,6 +4,7 @@
 
 use Symfony\Component\DependencyInjection\ContainerBuilder;
 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
 
 /**
  * Registers all event subscribers to the event dispatcher.
@@ -27,9 +28,8 @@ public function process(ContainerBuilder $container) {
       // the service is created by a factory.
       $class = $container->getDefinition($id)->getClass();
 
-      $refClass = new \ReflectionClass($class);
-      $interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface';
-      if (!$refClass->implementsInterface($interface)) {
+      $interface = EventSubscriberInterface::class;
+      if (!is_subclass_of($class, $interface)) {
         throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
       }
 
diff --git a/core/modules/language/src/ConfigurableLanguageManager.php b/core/modules/language/src/ConfigurableLanguageManager.php
index c4187aaf60b9..b39d7f3d2549 100644
--- a/core/modules/language/src/ConfigurableLanguageManager.php
+++ b/core/modules/language/src/ConfigurableLanguageManager.php
@@ -405,9 +405,7 @@ public function getFallbackCandidates(array $context = []) {
   public function getLanguageSwitchLinks($type, Url $url) {
     if ($this->negotiator) {
       foreach ($this->negotiator->getNegotiationMethods($type) as $method_id => $method) {
-        $reflector = new \ReflectionClass($method['class']);
-
-        if ($reflector->implementsInterface('\Drupal\language\LanguageSwitcherInterface')) {
+        if (is_subclass_of($method['class'], LanguageSwitcherInterface::class)) {
           $original_languages = $this->negotiatedLanguages;
           $result = $this->negotiator->getNegotiationMethodInstance($method_id)->getLanguageSwitchLinks($this->requestStack->getCurrentRequest(), $type, $url);
 
diff --git a/core/modules/language/src/HttpKernel/PathProcessorLanguage.php b/core/modules/language/src/HttpKernel/PathProcessorLanguage.php
index a5d5ecbb80b4..3aed7ecc2a8f 100644
--- a/core/modules/language/src/HttpKernel/PathProcessorLanguage.php
+++ b/core/modules/language/src/HttpKernel/PathProcessorLanguage.php
@@ -129,14 +129,13 @@ public function processOutbound($path, &$options = [], Request $request = NULL,
    *   The scope of the processors: "inbound" or "outbound".
    */
   protected function initProcessors($scope) {
-    $interface = '\Drupal\Core\PathProcessor\\' . Unicode::ucfirst($scope) . 'PathProcessorInterface';
+    $interface = 'Drupal\Core\PathProcessor\\' . Unicode::ucfirst($scope) . 'PathProcessorInterface';
     $this->processors[$scope] = [];
     $weights = [];
     foreach ($this->languageManager->getLanguageTypes() as $type) {
       foreach ($this->negotiator->getNegotiationMethods($type) as $method_id => $method) {
         if (!isset($this->processors[$scope][$method_id])) {
-          $reflector = new \ReflectionClass($method['class']);
-          if ($reflector->implementsInterface($interface)) {
+          if (is_subclass_of($method['class'], $interface)) {
             $this->processors[$scope][$method_id] = $this->negotiator->getNegotiationMethodInstance($method_id);
             $weights[$method_id] = $method['weight'];
           }
-- 
GitLab