FeaturesExtensionStorages.php
3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/**
* @file
* Contains \Drupal\features\FeaturesExtensionStorages.
*/
namespace Drupal\features;
use Drupal\Core\Config\InstallStorage;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Extension\Extension;
use Drupal\features\FeaturesInstallStorage;
/**
* Wraps FeaturesInstallStorage to support multiple configuration
* directories.
*/
class FeaturesExtensionStorages implements FeaturesExtensionStoragesInterface {
/**
* The target storage.
*
* @var \Drupal\Core\Config\StorageInterface
*/
protected $configStorage;
/**
* The extension storages.
*
* @var \Drupal\Core\Config\StorageInterface[]
*/
protected $extensionStorages;
/**
* The extension storages.
*
* @var \Drupal\Core\Config\StorageInterface[]
*/
protected $configurationLists;
/**
* Constructs a new FeaturesExtensionStorages object.
*
* @param \Drupal\Core\Config\StorageInterface $config_storage
* The configuration storage.
*/
public function __construct(StorageInterface $config_storage) {
$this->configStorage = $config_storage;
}
/**
* {@inheritdoc}
*/
public function getExtensionStorages() {
return $this->extensionStorages;
}
/**
* {@inheritdoc}
*/
public function addStorage($directory = InstallStorage::CONFIG_INSTALL_DIRECTORY) {
$this->extensionStorages[$directory] = new FeaturesInstallStorage($this->configStorage, $directory);
$this->reset();
}
/**
* {@inheritdoc}
*/
public function read($name) {
$list = $this->listAllByDirectory('');
if (isset($list[$name])) {
$directory = $list[$name];
return $this->extensionStorages[$directory]->read($name);
}
}
/**
* {@inheritdoc}
*/
public function listAll($prefix = '') {
return array_keys($this->listAllByDirectory($prefix));
}
/**
* {@inheritdoc}
*/
public function listExtensionConfig(Extension $extension) {
$extension_config = [];
foreach ($this->extensionStorages as $directory => $extension_storage) {
$extension_config = array_merge($extension_config, array_keys($extension_storage->getComponentNames([
$extension->getName() => $extension,
])));
}
return $extension_config;
}
/**
* Resets packages and configuration assignment.
*/
protected function reset() {
$this->configurationLists = [];
}
/**
* Returns a list of all configuration available from extensions.
*
* @param string $prefix
* (optional) The prefix to search for. If omitted, all configuration object
* names that exist are returned.
*
* @return array
* An array with configuration item names as keys and configuration
* directories as values.
*/
protected function listAllByDirectory($prefix = '') {
if (!isset($this->configurationLists[$prefix])) {
$this->configurationLists[$prefix] = [];
foreach ($this->extensionStorages as $directory => $extension_storage) {
$this->configurationLists[$prefix] += array_fill_keys($extension_storage->listAll($prefix), $directory);
}
}
return $this->configurationLists[$prefix];
}
}