Issue #3416826 by longwave, smustgrave, solideogloria, fgm: Queue factory services do not conform to an interface

merge-requests/6919/head
catch 2024-03-05 13:13:02 +00:00
parent 5c82c988fb
commit 2281800f86
3 changed files with 30 additions and 11 deletions

View File

@ -5,9 +5,9 @@ namespace Drupal\Core\Queue;
use Drupal\Core\Database\Connection; use Drupal\Core\Database\Connection;
/** /**
* Defines the key/value store factory for the database backend. * Defines the queue factory for the database backend.
*/ */
class QueueDatabaseFactory { class QueueDatabaseFactory implements QueueFactoryInterface {
/** /**
* The database connection. * The database connection.
@ -20,20 +20,14 @@ class QueueDatabaseFactory {
* Constructs this factory object. * Constructs this factory object.
* *
* @param \Drupal\Core\Database\Connection $connection * @param \Drupal\Core\Database\Connection $connection
* The Connection object containing the key-value tables. * The Connection object containing the queue table.
*/ */
public function __construct(Connection $connection) { public function __construct(Connection $connection) {
$this->connection = $connection; $this->connection = $connection;
} }
/** /**
* Constructs a new queue object for a given name. * {@inheritdoc}
*
* @param string $name
* The name of the collection holding key and value pairs.
*
* @return \Drupal\Core\Queue\DatabaseQueue
* A key/value store implementation for the given $collection.
*/ */
public function get($name) { public function get($name) {
return new DatabaseQueue($name, $this->connection); return new DatabaseQueue($name, $this->connection);

View File

@ -58,7 +58,11 @@ class QueueFactory implements ContainerAwareInterface {
if (empty($service_name)) { if (empty($service_name)) {
$service_name = $this->settings->get('queue_service_' . $name, $this->settings->get('queue_default', 'queue.database')); $service_name = $this->settings->get('queue_service_' . $name, $this->settings->get('queue_default', 'queue.database'));
} }
$this->queues[$name] = $this->container->get($service_name)->get($name); $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]; return $this->queues[$name];
} }

View File

@ -0,0 +1,21 @@
<?php
namespace Drupal\Core\Queue;
/**
* An interface defining queue factory classes.
*/
interface QueueFactoryInterface {
/**
* Constructs a new queue object for a given name.
*
* @param string $name
* The name of the queue.
*
* @return \Drupal\Core\Queue\QueueInterface
* The queue object.
*/
public function get($name);
}