3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
35 * An extension container is a locally-accessible source tree which can be
36 * scanned for extensions.
38 class CRM_Extension_Container_Collection
implements CRM_Extension_Container_Interface
{
41 * @var array ($name => CRM_Extension_Container_Interface)
43 * Note: Treat as private. This is only public to facilitate debugging.
48 * @var CRM_Utils_Cache_Interface|NULL
50 * Note: Treat as private. This is only public to facilitate debugging.
55 * @var string the cache key used for any data stored by this container
57 * Note: Treat as private. This is only public to facilitate debugging.
62 * @var array ($key => $containerName)
64 * Note: Treat as private. This is only public to facilitate debugging.
69 * @param array $containers array($name => CRM_Extension_Container_Interface) in order from highest priority (winners) to lowest priority (losers)
70 * @param CRM_Utils_Cache_Interface $cache
71 * @param string $cacheKey unique name for this container
73 public function __construct($containers, CRM_Utils_Cache_Interface
$cache = NULL, $cacheKey = NULL) {
74 $this->containers
= $containers;
75 $this->cache
= $cache;
76 $this->cacheKey
= $cacheKey;
82 public function checkRequirements() {
84 foreach ($this->containers
as $container) {
85 $errors = array_merge($errors, $container->checkRequirements());
93 public function getKeys() {
94 $k2c = $this->getKeysToContainer();
95 return array_keys($k2c);
101 public function getPath($key) {
102 return $this->getContainer($key)->getPath($key);
108 public function getResUrl($key) {
109 return $this->getContainer($key)->getResUrl($key);
115 public function refresh() {
117 $this->cache
->delete($this->cacheKey
);
119 foreach ($this->containers
as $container) {
120 $container->refresh();
125 * Get the container which defines a particular key
129 * @throws CRM_Extension_Exception_MissingException
130 * @return CRM_Extension_Container_Interface
132 public function getContainer($key) {
133 $k2c = $this->getKeysToContainer();
134 if (isset($k2c[$key]) && isset($this->containers
[$k2c[$key]])) {
135 return $this->containers
[$k2c[$key]];
137 throw new CRM_Extension_Exception_MissingException("Unknown extension: $key");
142 * Get a list of all keys in these containers -- and the
143 * name of the container which defines each key.
145 * @return array ($key => $containerName)
147 public function getKeysToContainer() {
149 $k2c = $this->cache
->get($this->cacheKey
);
151 if (!is_array($k2c)) {
153 $containerNames = array_reverse(array_keys($this->containers
));
154 foreach ($containerNames as $name) {
155 $keys = $this->containers
[$name]->getKeys();
156 foreach ($keys as $key) {
161 $this->cache
->set($this->cacheKey
, $k2c);