Issue #3416357 by longwave, arunkumark, taraskorpach, Spokje, andypost: Convert QueueFactory to use a service locator

merge-requests/5987/merge
catch 2024-03-18 15:43:11 +00:00
parent 1bcc7f34e6
commit dd446b636e
4 changed files with 18 additions and 25 deletions

View File

@ -519,18 +519,6 @@ $ignoreErrors[] = [
'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,

View File

@ -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

View File

@ -24,6 +24,7 @@ use Drupal\Core\DependencyInjection\ContainerBuilder;
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 @@ class CoreServiceProvider implements ServiceProviderInterface, ServiceModifierIn
$container->registerForAutoconfiguration(LoggerAwareInterface::class)
->addTag('logger_aware');
$container->registerForAutoconfiguration(QueueFactoryInterface::class)
->addTag('queue_factory');
}
/**

View File

@ -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 @@ class QueueFactory implements ContainerAwareInterface {
$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];