From dd446b636eda9a8262891f4769f2573d75cc22e2 Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Mon, 18 Mar 2024 15:43:11 +0000
Subject: [PATCH] Issue #3416357 by longwave, arunkumark, taraskorpach, Spokje,
 andypost: Convert QueueFactory to use a service locator

---
 core/.phpstan-baseline.php                   | 12 ----------
 core/core.services.yml                       |  4 +---
 core/lib/Drupal/Core/CoreServiceProvider.php |  3 +++
 core/lib/Drupal/Core/Queue/QueueFactory.php  | 24 ++++++++++++--------
 4 files changed, 18 insertions(+), 25 deletions(-)

diff --git a/core/.phpstan-baseline.php b/core/.phpstan-baseline.php
index 8503a727d9f8..31df6665c84a 100644
--- a/core/.phpstan-baseline.php
+++ b/core/.phpstan-baseline.php
@@ -519,18 +519,6 @@
 	'count' => 1,
 	'path' => __DIR__ . '/lib/Drupal/Core/Queue/Memory.php',
 ];
-$ignoreErrors[] = [
-	'message' => '#^Class Drupal\\\\Core\\\\Queue\\\\QueueFactory implements deprecated interface Symfony\\\\Component\\\\DependencyInjection\\\\ContainerAwareInterface\\:
-since Symfony 6\\.4, use dependency injection instead$#',
-	'count' => 1,
-	'path' => __DIR__ . '/lib/Drupal/Core/Queue/QueueFactory.php',
-];
-$ignoreErrors[] = [
-	'message' => '#^Usage of deprecated trait Symfony\\\\Component\\\\DependencyInjection\\\\ContainerAwareTrait in class Drupal\\\\Core\\\\Queue\\\\QueueFactory\\:
-since Symfony 6\\.4, use dependency injection instead$#',
-	'count' => 1,
-	'path' => __DIR__ . '/lib/Drupal/Core/Queue/QueueFactory.php',
-];
 $ignoreErrors[] = [
 	'message' => '#^Variable \\$sort in isset\\(\\) always exists and is not nullable\\.$#',
 	'count' => 1,
diff --git a/core/core.services.yml b/core/core.services.yml
index 7f5ec7d25d93..b97667e9e618 100644
--- a/core/core.services.yml
+++ b/core/core.services.yml
@@ -556,9 +556,7 @@ services:
   Drupal\Core\State\StateInterface: '@state'
   queue:
     class: Drupal\Core\Queue\QueueFactory
-    arguments: ['@settings']
-    calls:
-      - [setContainer, ['@service_container']]
+    autowire: true
   Drupal\Core\Queue\QueueFactory: '@queue'
   queue.database:
     class: Drupal\Core\Queue\QueueDatabaseFactory
diff --git a/core/lib/Drupal/Core/CoreServiceProvider.php b/core/lib/Drupal/Core/CoreServiceProvider.php
index 5fb8d9360219..28c09a417f00 100644
--- a/core/lib/Drupal/Core/CoreServiceProvider.php
+++ b/core/lib/Drupal/Core/CoreServiceProvider.php
@@ -24,6 +24,7 @@
 use Drupal\Core\DependencyInjection\ServiceModifierInterface;
 use Drupal\Core\DependencyInjection\ServiceProviderInterface;
 use Drupal\Core\Plugin\PluginManagerPass;
+use Drupal\Core\Queue\QueueFactoryInterface;
 use Drupal\Core\Render\MainContent\MainContentRenderersPass;
 use Drupal\Core\Site\Settings;
 use Psr\Log\LoggerAwareInterface;
@@ -106,6 +107,8 @@ public function register(ContainerBuilder $container) {
     $container->registerForAutoconfiguration(LoggerAwareInterface::class)
       ->addTag('logger_aware');
 
+    $container->registerForAutoconfiguration(QueueFactoryInterface::class)
+      ->addTag('queue_factory');
   }
 
   /**
diff --git a/core/lib/Drupal/Core/Queue/QueueFactory.php b/core/lib/Drupal/Core/Queue/QueueFactory.php
index 0fb33da2a20a..f17c391ad3bf 100644
--- a/core/lib/Drupal/Core/Queue/QueueFactory.php
+++ b/core/lib/Drupal/Core/Queue/QueueFactory.php
@@ -3,15 +3,13 @@
 namespace Drupal\Core\Queue;
 
 use Drupal\Core\Site\Settings;
-use Symfony\Component\DependencyInjection\ContainerAwareInterface;
-use Symfony\Component\DependencyInjection\ContainerAwareTrait;
+use Psr\Container\ContainerInterface;
+use Symfony\Component\DependencyInjection\Attribute\AutowireLocator;
 
 /**
  * Defines the queue factory.
  */
-class QueueFactory implements ContainerAwareInterface {
-
-  use ContainerAwareTrait;
+class QueueFactory {
 
   /**
    * Instantiated queues, keyed by name.
@@ -28,9 +26,18 @@ class QueueFactory implements ContainerAwareInterface {
   protected $settings;
 
   /**
-   * Constructs a queue factory.
+   * Constructs QueueFactory object.
+   *
+   * @param \Drupal\Core\Site\Settings $settings
+   *   The site settings.
+   * @param \Psr\Container\ContainerInterface $container
+   *   A service locator that contains the queue services.
    */
-  public function __construct(Settings $settings) {
+  public function __construct(
+    Settings $settings,
+    #[AutowireLocator('queue_factory')]
+    protected ContainerInterface $container,
+  ) {
     $this->settings = $settings;
   }
 
@@ -59,9 +66,6 @@ public function get($name, $reliable = FALSE) {
         $service_name = $this->settings->get('queue_service_' . $name, $this->settings->get('queue_default', 'queue.database'));
       }
       $factory = $this->container->get($service_name);
-      if (!$factory instanceof QueueFactoryInterface) {
-        @trigger_error(sprintf('Not implementing %s in %s is deprecated in drupal:10.3.0 and the factory will not be discovered in drupal:11.0.0. Implement the interface in your factory class. See https://www.drupal.org/node/3417034', QueueFactoryInterface::class, $factory::class), E_USER_DEPRECATED);
-      }
       $this->queues[$name] = $factory->get($name);
     }
     return $this->queues[$name];
-- 
GitLab