3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
30 * @copyright CiviCRM LLC (c) 2004-2019
34 * An extension container is a locally-accessible source tree which can be
35 * scanned for extensions.
37 class CRM_Extension_Container_Collection
implements CRM_Extension_Container_Interface
{
42 * Format is [$name => CRM_Extension_Container_Interface]
44 * @var [string => CRM_Extension_Container_Interface]
46 * Note: Treat as private. This is only public to facilitate debugging.
51 * @var CRM_Utils_Cache_Interface|null
53 * Note: Treat as private. This is only public to facilitate debugging.
58 * @var string the cache key used for any data stored by this container
60 * Note: Treat as private. This is only public to facilitate debugging.
67 * Format is ($key => $containerName).
71 * Note: Treat as private. This is only public to facilitate debugging.
78 * @param array $containers
79 * Array($name => CRM_Extension_Container_Interface) in order from highest
80 * priority (winners) to lowest priority (losers).
81 * @param CRM_Utils_Cache_Interface $cache
82 * Cache in which to store extension metadata.
83 * @param string $cacheKey
84 * Unique name for this container.
86 public function __construct($containers, CRM_Utils_Cache_Interface
$cache = NULL, $cacheKey = NULL) {
87 $this->containers
= $containers;
88 $this->cache
= $cache;
89 $this->cacheKey
= $cacheKey;
97 public function checkRequirements() {
99 foreach ($this->containers
as $container) {
100 $errors = array_merge($errors, $container->checkRequirements());
110 public function getKeys() {
111 $k2c = $this->getKeysToContainer();
112 return array_keys($k2c);
120 * @throws \CRM_Extension_Exception_MissingException
122 public function getPath($key) {
123 return $this->getContainer($key)->getPath($key);
131 * @throws \CRM_Extension_Exception_MissingException
133 public function getResUrl($key) {
134 return $this->getContainer($key)->getResUrl($key);
140 public function refresh() {
142 $this->cache
->delete($this->cacheKey
);
144 foreach ($this->containers
as $container) {
145 $container->refresh();
150 * Get the container which defines a particular key.
155 * @throws CRM_Extension_Exception_MissingException
156 * @return CRM_Extension_Container_Interface
158 public function getContainer($key) {
159 $k2c = $this->getKeysToContainer();
160 if (isset($k2c[$key]) && isset($this->containers
[$k2c[$key]])) {
161 return $this->containers
[$k2c[$key]];
164 throw new CRM_Extension_Exception_MissingException("Unknown extension: $key");
169 * Get a list of all keys in these containers -- and the
170 * name of the container which defines each key.
173 * ($key => $containerName)
175 public function getKeysToContainer() {
177 $k2c = $this->cache
->get($this->cacheKey
);
179 if (!isset($k2c) ||
!is_array($k2c)) {
181 $containerNames = array_reverse(array_keys($this->containers
));
182 foreach ($containerNames as $name) {
183 $keys = $this->containers
[$name]->getKeys();
184 foreach ($keys as $key) {
189 $this->cache
->set($this->cacheKey
, $k2c);