3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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-2016
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
{
40 * @var array ($name => CRM_Extension_Container_Interface)
42 * Note: Treat as private. This is only public to facilitate debugging.
47 * @var CRM_Utils_Cache_Interface|NULL
49 * Note: Treat as private. This is only public to facilitate debugging.
54 * @var string the cache key used for any data stored by this container
56 * Note: Treat as private. This is only public to facilitate debugging.
61 * @var array ($key => $containerName)
63 * Note: Treat as private. This is only public to facilitate debugging.
68 * @param array $containers
69 * Array($name => CRM_Extension_Container_Interface) in order from highest
70 * priority (winners) to lowest priority (losers).
71 * @param CRM_Utils_Cache_Interface $cache
72 * Cache in which to store extension metadata.
73 * @param string $cacheKey
74 * Unique name for this container.
76 public function __construct($containers, CRM_Utils_Cache_Interface
$cache = NULL, $cacheKey = NULL) {
77 $this->containers
= $containers;
78 $this->cache
= $cache;
79 $this->cacheKey
= $cacheKey;
87 public function checkRequirements() {
89 foreach ($this->containers
as $container) {
90 $errors = array_merge($errors, $container->checkRequirements());
100 public function getKeys() {
101 $k2c = $this->getKeysToContainer();
102 return array_keys($k2c);
110 public function getPath($key) {
111 return $this->getContainer($key)->getPath($key);
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);