class QueueFactory

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Queue/QueueFactory.php \Drupal\Core\Queue\QueueFactory
  2. 8.9.x core/lib/Drupal/Core/Queue/QueueFactory.php \Drupal\Core\Queue\QueueFactory
  3. 10 core/lib/Drupal/Core/Queue/QueueFactory.php \Drupal\Core\Queue\QueueFactory

Defines the queue factory.

Hierarchy

Expanded class hierarchy of QueueFactory

10 files declare their use of QueueFactory
ApiController.php in core/modules/package_manager/tests/modules/package_manager_test_api/src/ApiController.php
Cron.php in core/lib/Drupal/Core/Cron.php
CronSuspendQueueDelayTest.php in core/tests/Drupal/Tests/Core/Cron/CronSuspendQueueDelayTest.php
DirectWriteTest.php in core/modules/package_manager/tests/src/Kernel/DirectWriteTest.php
PackageManagerKernelTestBase.php in core/modules/package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php

... See full list

1 string reference to 'QueueFactory'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses QueueFactory
queue in core/core.services.yml
Drupal\Core\Queue\QueueFactory

File

core/lib/Drupal/Core/Queue/QueueFactory.php, line 12

Namespace

Drupal\Core\Queue
View source
class QueueFactory {
  
  /**
   * Instantiated queues, keyed by name.
   *
   * @var array
   */
  protected $queues = [];
  
  /**
   * The settings object.
   *
   * @var \Drupal\Core\Site\Settings
   */
  protected $settings;
  
  /**
   * 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, #[AutowireLocator('queue_factory')] protected ContainerInterface $container) {
    $this->settings = $settings;
  }
  
  /**
   * Constructs a new queue.
   *
   * @param string $name
   *   The name of the queue to work with.
   * @param bool $reliable
   *   (optional) TRUE if the ordering of items and guaranteeing every item
   *   executes at least once is important, FALSE if scalability is the main
   *   concern. Defaults to FALSE.
   *
   * @return \Drupal\Core\Queue\QueueInterface
   *   A queue implementation for the given name.
   */
  public function get($name, $reliable = FALSE) {
    if (!isset($this->queues[$name])) {
      // If it is a reliable queue, check the specific settings first.
      if ($reliable) {
        $service_name = $this->settings
          ->get('queue_reliable_service_' . $name);
      }
      // If no reliable queue was defined, check the service and global
      // settings, fall back to queue.database.
      if (empty($service_name)) {
        $service_name = $this->settings
          ->get('queue_service_' . $name, $this->settings
          ->get('queue_default', 'queue.database'));
      }
      $factory = $this->container
        ->get($service_name);
      $this->queues[$name] = $factory->get($name);
    }
    return $this->queues[$name];
  }

}

Members

Title Sort descending Modifiers Object type Summary
QueueFactory::$queues protected property Instantiated queues, keyed by name.
QueueFactory::$settings protected property The settings object.
QueueFactory::get public function Constructs a new queue.
QueueFactory::__construct public function Constructs QueueFactory object.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.