3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
14 * @copyright CiviCRM LLC https://civicrm.org/licensing
18 * An extension container is a locally-accessible source tree which can be
19 * scanned for extensions.
21 class CRM_Extension_Container_Collection
implements CRM_Extension_Container_Interface
{
26 * Format is [$name => CRM_Extension_Container_Interface]
30 * Note: Treat as private. This is only public to facilitate debugging.
35 * @var CRM_Utils_Cache_Interface|null
37 * Note: Treat as private. This is only public to facilitate debugging.
42 * The cache key used for any data stored by this container.
46 * Note: Treat as private. This is only public to facilitate debugging.
53 * Format is ($key => $containerName).
57 * Note: Treat as private. This is only public to facilitate debugging.
64 * @param array $containers
65 * Array($name => CRM_Extension_Container_Interface) in order from highest
66 * priority (winners) to lowest priority (losers).
67 * @param CRM_Utils_Cache_Interface $cache
68 * Cache in which to store extension metadata.
69 * @param string $cacheKey
70 * Unique name for this container.
72 public function __construct($containers, CRM_Utils_Cache_Interface
$cache = NULL, $cacheKey = NULL) {
73 $this->containers
= $containers;
74 $this->cache
= $cache;
75 $this->cacheKey
= $cacheKey;
83 public function checkRequirements() {
85 foreach ($this->containers
as $container) {
86 $errors = array_merge($errors, $container->checkRequirements());
96 public function getKeys() {
97 $k2c = $this->getKeysToContainer();
98 return array_keys($k2c);
106 * @throws \CRM_Extension_Exception_MissingException
108 public function getPath($key) {
109 return $this->getContainer($key)->getPath($key);
117 * @throws \CRM_Extension_Exception_MissingException
119 public function getResUrl($key) {
120 return $this->getContainer($key)->getResUrl($key);
126 public function refresh() {
128 $this->cache
->delete($this->cacheKey
);
130 foreach ($this->containers
as $container) {
131 $container->refresh();
136 * Get the container which defines a particular key.
141 * @throws CRM_Extension_Exception_MissingException
142 * @return CRM_Extension_Container_Interface
144 public function getContainer($key) {
145 $k2c = $this->getKeysToContainer();
146 if (isset($k2c[$key]) && isset($this->containers
[$k2c[$key]])) {
147 return $this->containers
[$k2c[$key]];
150 throw new CRM_Extension_Exception_MissingException("Unknown extension: $key");
155 * Get a list of all keys in these containers -- and the
156 * name of the container which defines each key.
159 * ($key => $containerName)
161 public function getKeysToContainer() {
163 $k2c = $this->cache
->get($this->cacheKey
);
165 if (!isset($k2c) ||
!is_array($k2c)) {
167 $containerNames = array_reverse(array_keys($this->containers
));
168 foreach ($containerNames as $name) {
169 $keys = $this->containers
[$name]->getKeys();
170 foreach ($keys as $key) {
175 $this->cache
->set($this->cacheKey
, $k2c);