Patched to Drupal 8.4.8 level. See https://www.drupal.org/sa-core-2018-004 and patch...
[yaffs-website] / web / core / lib / Drupal / Core / Queue / QueueFactory.php
1 <?php
2
3 namespace Drupal\Core\Queue;
4
5 use Drupal\Core\Site\Settings;
6 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
7 use Symfony\Component\DependencyInjection\ContainerAwareTrait;
8
9 /**
10  * Defines the queue factory.
11  */
12 class QueueFactory implements ContainerAwareInterface {
13
14   use ContainerAwareTrait;
15
16   /**
17    * Instantiated queues, keyed by name.
18    *
19    * @var array
20    */
21   protected $queues = [];
22
23   /**
24    * The settings object.
25    *
26    * @var \Drupal\Core\Site\Settings
27    */
28   protected $settings;
29
30
31   /**
32    * Constructs a queue factory.
33    */
34   public function __construct(Settings $settings) {
35     $this->settings = $settings;
36   }
37
38   /**
39    * Constructs a new queue.
40    *
41    * @param string $name
42    *   The name of the queue to work with.
43    * @param bool $reliable
44    *   (optional) TRUE if the ordering of items and guaranteeing every item executes at
45    *   least once is important, FALSE if scalability is the main concern. Defaults
46    *   to FALSE.
47    *
48    * @return \Drupal\Core\Queue\QueueInterface
49    *   A queue implementation for the given name.
50    */
51   public function get($name, $reliable = FALSE) {
52     if (!isset($this->queues[$name])) {
53       // If it is a reliable queue, check the specific settings first.
54       if ($reliable) {
55         $service_name = $this->settings->get('queue_reliable_service_' . $name);
56       }
57       // If no reliable queue was defined, check the service and global
58       // settings, fall back to queue.database.
59       if (empty($service_name)) {
60         $service_name = $this->settings->get('queue_service_' . $name, $this->settings->get('queue_default', 'queue.database'));
61       }
62       $this->queues[$name] = $this->container->get($service_name)->get($name);
63     }
64     return $this->queues[$name];
65   }
66
67 }