diff --git a/core/.phpstan-baseline.php b/core/.phpstan-baseline.php index 8503a727d9f844b51c64c9174b3baedbc18057d0..31df6665c84a43121bc31cd68d2041d705efed22 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 7f5ec7d25d93e8115b9870577d7924b18fe59701..b97667e9e618039c44b62cbf8cb26179d2e2fdef 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 5fb8d9360219b67dac18ba2cafc67f2c66150c08..28c09a417f00faa6e460391fd2b58fb2d376a07b 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 0fb33da2a20a6ddec73fdaf355d98c2d62a3d0e3..f17c391ad3bfc7f9c1c6c93436f7bd8c940d7a58 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];