3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
35 * An extension container is a locally-accessible source tree which can be
36 * scanned for extensions.
38 class CRM_Extension_Container_Basic
implements CRM_Extension_Container_Interface
{
43 * Note: Treat as private. This is only public to facilitate debugging.
50 * Note: Treat as private. This is only public to facilitate debugging.
55 * @var CRM_Utils_Cache_Interface|NULL
57 * Note: Treat as private. This is only public to facilitate debugging.
62 * @var string the cache key used for any data stored by this container
64 * Note: Treat as private. This is only public to facilitate debugging.
69 * @var array($key => $relPath)
71 * Note: Treat as private. This is only public to facilitate debugging.
73 public $relPaths = FALSE;
76 * @param string $baseDir local path to the container
77 * @param string $baseUrl public URL of the container
78 * @param CRM_Utils_Cache_Interface $cache
79 * @param string $cacheKey unique name for this container
81 public function __construct($baseDir, $baseUrl, CRM_Utils_Cache_Interface
$cache = NULL, $cacheKey = NULL) {
82 $this->cache
= $cache;
83 $this->cacheKey
= $cacheKey;
84 $this->baseDir
= rtrim($baseDir, '/');
85 $this->baseUrl
= rtrim($baseUrl, '/');
91 public function getKeys() {
92 return array_keys($this->getRelPaths());
98 public function getPath($key) {
99 return $this->baseDir
. $this->getRelPath($key);
105 public function getResUrl($key) {
106 return $this->baseUrl
. $this->getRelPath($key);
112 public function refresh() {
113 $this->relPaths
= NULL;
115 $this->cache
->delete($this->cacheKey
);
122 public function getBaseDir() {
123 return $this->baseDir
;
127 * Determine the relative path of an extension directory
130 * @throws CRM_Extension_Exception
132 protected function getRelPath($key) {
133 $keypaths = $this->getRelPaths();
134 if (! isset($keypaths[$key])) {
135 throw new CRM_Extension_Exception_MissingException("Failed to find extension: $key");
137 return $keypaths[$key];
141 * Scan $basedir for a list of extension-keys
143 * @return array($key => $relPath)
145 protected function getRelPaths() {
146 if (!is_array($this->relPaths
)) {
148 $this->relPaths
= $this->cache
->get($this->cacheKey
);
150 if (!is_array($this->relPaths
)) {
151 $this->relPaths
= array();
152 $infoPaths = CRM_Utils_File
::findFiles($this->baseDir
, 'info.xml');
153 foreach ($infoPaths as $infoPath) {
154 $relPath = CRM_Utils_File
::relativize(dirname($infoPath), $this->baseDir
);
156 $info = CRM_Extension_Info
::loadFromFile($infoPath);
157 } catch (CRM_Extension_Exception_ParseException
$e) {
158 CRM_Core_Session
::setStatus(ts('Parse error in extension: %1', array(
159 1 => $e->getMessage(),
161 CRM_Core_Error
::debug_log_message("Parse error in extension: " . $e->getMessage());
164 $this->relPaths
[$info->key
] = $relPath;
167 $this->cache
->set($this->cacheKey
, $this->relPaths
);
171 return $this->relPaths
;