Pull merge.
[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    * Constructs a queue factory.
32    */
33   public function __construct(Settings $settings) {
34     $this->settings = $settings;
35   }
36
37   /**
38    * Constructs a new queue.
39    *
40    * @param string $name
41    *   The name of the queue to work with.
42    * @param bool $reliable
43    *   (optional) TRUE if the ordering of items and guaranteeing every item executes at
44    *   least once is important, FALSE if scalability is the main concern. Defaults
45    *   to FALSE.
46    *
47    * @return \Drupal\Core\Queue\QueueInterface
48    *   A queue implementation for the given name.
49    */
50   public function get($name, $reliable = FALSE) {
51     if (!isset($this->queues[$name])) {
52       // If it is a reliable queue, check the specific settings first.
53       if ($reliable) {
54         $service_name = $this->settings->get('queue_reliable_service_' . $name);
55       }
56       // If no reliable queue was defined, check the service and global
57       // settings, fall back to queue.database.
58       if (empty($service_name)) {
59         $service_name = $this->settings->get('queue_service_' . $name, $this->settings->get('queue_default', 'queue.database'));
60       }
61       $this->queues[$name] = $this->container->get($service_name)->get($name);
62     }
63     return $this->queues[$name];
64   }
65
66 }