Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Core\Config;
|
Chris@0
|
4
|
Chris@0
|
5 use Symfony\Component\EventDispatcher\Event;
|
Chris@0
|
6
|
Chris@0
|
7 /**
|
Chris@0
|
8 * Gets information on all the possible configuration collections.
|
Chris@0
|
9 */
|
Chris@0
|
10 class ConfigCollectionInfo extends Event {
|
Chris@0
|
11
|
Chris@0
|
12 /**
|
Chris@0
|
13 * Configuration collection information keyed by collection name.
|
Chris@0
|
14 *
|
Chris@0
|
15 * The value is either the configuration factory override that is responsible
|
Chris@0
|
16 * for the collection or null if there is not one.
|
Chris@0
|
17 *
|
Chris@0
|
18 * @var array
|
Chris@0
|
19 */
|
Chris@0
|
20 protected $collections = [];
|
Chris@0
|
21
|
Chris@0
|
22 /**
|
Chris@0
|
23 * Adds a collection to the list of possible collections.
|
Chris@0
|
24 *
|
Chris@0
|
25 * @param string $collection
|
Chris@0
|
26 * Collection name to add.
|
Chris@0
|
27 * @param \Drupal\Core\Config\ConfigFactoryOverrideInterface $override_service
|
Chris@0
|
28 * (optional) The configuration factory override service responsible for the
|
Chris@0
|
29 * collection.
|
Chris@0
|
30 *
|
Chris@0
|
31 * @throws \InvalidArgumentException
|
Chris@0
|
32 * Exception thrown if $collection is equal to
|
Chris@0
|
33 * \Drupal\Core\Config\StorageInterface::DEFAULT_COLLECTION.
|
Chris@0
|
34 */
|
Chris@0
|
35 public function addCollection($collection, ConfigFactoryOverrideInterface $override_service = NULL) {
|
Chris@0
|
36 if ($collection == StorageInterface::DEFAULT_COLLECTION) {
|
Chris@0
|
37 throw new \InvalidArgumentException('Can not add the default collection to the ConfigCollectionInfo object');
|
Chris@0
|
38 }
|
Chris@0
|
39 $this->collections[$collection] = $override_service;
|
Chris@0
|
40 }
|
Chris@0
|
41
|
Chris@0
|
42 /**
|
Chris@0
|
43 * Gets the list of possible collection names.
|
Chris@0
|
44 *
|
Chris@0
|
45 * @param bool $include_default
|
Chris@0
|
46 * (Optional) Include the default collection. Defaults to TRUE.
|
Chris@0
|
47 *
|
Chris@0
|
48 * @return array
|
Chris@0
|
49 * The list of possible collection names.
|
Chris@0
|
50 */
|
Chris@0
|
51 public function getCollectionNames($include_default = TRUE) {
|
Chris@0
|
52 $collection_names = array_keys($this->collections);
|
Chris@0
|
53 sort($collection_names);
|
Chris@0
|
54 if ($include_default) {
|
Chris@0
|
55 array_unshift($collection_names, StorageInterface::DEFAULT_COLLECTION);
|
Chris@0
|
56 }
|
Chris@0
|
57 return $collection_names;
|
Chris@0
|
58 }
|
Chris@0
|
59
|
Chris@0
|
60 /**
|
Chris@0
|
61 * Gets the config factory override service responsible for the collection.
|
Chris@0
|
62 *
|
Chris@0
|
63 * @param string $collection
|
Chris@0
|
64 * The configuration collection.
|
Chris@0
|
65 *
|
Chris@0
|
66 * @return \Drupal\Core\Config\ConfigFactoryOverrideInterface|null
|
Chris@0
|
67 * The override service responsible for the collection if one exists. NULL
|
Chris@0
|
68 * if not.
|
Chris@0
|
69 */
|
Chris@0
|
70 public function getOverrideService($collection) {
|
Chris@0
|
71 return isset($this->collections[$collection]) ? $this->collections[$collection] : NULL;
|
Chris@0
|
72 }
|
Chris@0
|
73
|
Chris@0
|
74 }
|