$relPath) * * Note: Treat as private. This is only public to facilitate debugging. */ public $relPaths = FALSE; /** * @param string $baseDir local path to the container * @param string $baseUrl public URL of the container * @param CRM_Utils_Cache_Interface $cache * @param string $cacheKey unique name for this container */ public function __construct($baseDir, $baseUrl, CRM_Utils_Cache_Interface $cache = NULL, $cacheKey = NULL) { $this->cache = $cache; $this->cacheKey = $cacheKey; $this->baseDir = rtrim($baseDir, '/'); $this->baseUrl = rtrim($baseUrl, '/'); } /** * {@inheritdoc} */ public function getKeys() { return array_keys($this->getRelPaths()); } /** * {@inheritdoc} */ public function getPath($key) { return $this->baseDir . $this->getRelPath($key); } /** * {@inheritdoc} */ public function getResUrl($key) { return $this->baseUrl . $this->getRelPath($key); } /** * {@inheritdoc} */ public function refresh() { $this->relPaths = NULL; if ($this->cache) { $this->cache->delete($this->cacheKey); } } /** * @return string */ public function getBaseDir() { return $this->baseDir; } /** * Determine the relative path of an extension directory * * @return string * @throws CRM_Extension_Exception */ protected function getRelPath($key) { $keypaths = $this->getRelPaths(); if (! isset($keypaths[$key])) { throw new CRM_Extension_Exception_MissingException("Failed to find extension: $key"); } return $keypaths[$key]; } /** * Scan $basedir for a list of extension-keys * * @return array($key => $relPath) */ protected function getRelPaths() { if (!is_array($this->relPaths)) { if ($this->cache) { $this->relPaths = $this->cache->get($this->cacheKey); } if (!is_array($this->relPaths)) { $this->relPaths = array(); $infoPaths = CRM_Utils_File::findFiles($this->baseDir, 'info.xml'); foreach ($infoPaths as $infoPath) { $relPath = CRM_Utils_File::relativize(dirname($infoPath), $this->baseDir); try { $info = CRM_Extension_Info::loadFromFile($infoPath); } catch (CRM_Extension_Exception_ParseException $e) { CRM_Core_Session::setStatus(ts('Parse error in extension: %1', array( 1 => $e->getMessage(), )), '', 'error'); CRM_Core_Error::debug_log_message("Parse error in extension: " . $e->getMessage()); continue; } $this->relPaths[$info->key] = $relPath; } if ($this->cache) { $this->cache->set($this->cacheKey, $this->relPaths); } } } return $this->relPaths; } }