parameters); } else { self::$singleton = new CRM_Extension_System(); } } return self::$singleton; } /** * @param CRM_Extension_System $singleton * The new, singleton extension system. */ public static function setSingleton(CRM_Extension_System $singleton) { self::$singleton = $singleton; } /** * @param array $parameters * List of configuration values required by the extension system. * Missing values will be guessed based on $config. */ public function __construct($parameters = array()) { $config = CRM_Core_Config::singleton(); $configKeys = array( 'extensionsDir', 'extensionsURL', 'resourceBase', 'userFrameworkBaseURL', ); foreach ($configKeys as $key) { if (!array_key_exists($key, $parameters)) { $parameters[$key] = $config->{$key}; } } if (!array_key_exists('civicrm_root', $parameters)) { $parameters['civicrm_root'] = $GLOBALS['civicrm_root']; } if (!array_key_exists('cmsRootPath', $parameters)) { $parameters['cmsRootPath'] = $config->userSystem->cmsRootPath(); } if (!array_key_exists('domain_id', $parameters)) { $parameters['domain_id'] = CRM_Core_Config::domainID(); } ksort($parameters); // guaranteed ordering - useful for md5(serialize($parameters)) $this->parameters = $parameters; } /** * Get a container which represents all available extensions. * * @return CRM_Extension_Container_Interface */ public function getFullContainer() { if ($this->fullContainer === NULL) { $containers = array(); if ($this->getDefaultContainer()) { $containers['default'] = $this->getDefaultContainer(); } $containers['civiroot'] = new CRM_Extension_Container_Basic( $this->parameters['civicrm_root'], $this->parameters['resourceBase'], $this->getCache(), 'civiroot' ); // TODO: CRM_Extension_Container_Basic( /sites/all/modules ) // TODO: CRM_Extension_Container_Basic( /sites/$domain/modules // TODO: CRM_Extension_Container_Basic( /modules ) // TODO: CRM_Extension_Container_Basic( /vendors ) // At time of writing, D6, D7, and WP support cmsRootPath() but J does not if (NULL !== $this->parameters['cmsRootPath']) { $vendorPath = $this->parameters['cmsRootPath'] . DIRECTORY_SEPARATOR . 'vendor'; if (is_dir($vendorPath)) { $containers['cmsvendor'] = new CRM_Extension_Container_Basic( $vendorPath, $this->parameters['userFrameworkBaseURL'] . DIRECTORY_SEPARATOR . 'vendor', $this->getCache(), 'cmsvendor' ); } } $this->fullContainer = new CRM_Extension_Container_Collection($containers, $this->getCache(), 'full'); } return $this->fullContainer; } /** * Get the container to which new extensions are installed. * * This container should be a particular, writeable directory. * * @return CRM_Extension_Container_Default|FALSE (false if not configured) */ public function getDefaultContainer() { if ($this->defaultContainer === NULL) { if ($this->parameters['extensionsDir']) { $this->defaultContainer = new CRM_Extension_Container_Default($this->parameters['extensionsDir'], $this->parameters['extensionsURL'], $this->getCache(), 'default'); } else { $this->defaultContainer = FALSE; } } return $this->defaultContainer; } /** * Get the service which provides runtime information about extensions. * * @return CRM_Extension_Mapper */ public function getMapper() { if ($this->mapper === NULL) { $this->mapper = new CRM_Extension_Mapper($this->getFullContainer(), $this->getCache(), 'mapper'); } return $this->mapper; } /** * Get the service for enabling and disabling extensions. * * @return CRM_Extension_Manager */ public function getManager() { if ($this->manager === NULL) { $typeManagers = array( 'payment' => new CRM_Extension_Manager_Payment($this->getMapper()), 'report' => new CRM_Extension_Manager_Report(), 'search' => new CRM_Extension_Manager_Search(), 'module' => new CRM_Extension_Manager_Module($this->getMapper()), ); $this->manager = new CRM_Extension_Manager($this->getFullContainer(), $this->getDefaultContainer(), $this->getMapper(), $typeManagers); } return $this->manager; } /** * Get the service for finding remotely-available extensions * * @return CRM_Extension_Browser */ public function getBrowser() { if ($this->browser === NULL) { $cacheDir = NULL; if ($this->getDefaultContainer()) { $cacheDir = $this->getDefaultContainer()->getBaseDir() . DIRECTORY_SEPARATOR . 'cache'; } $this->browser = new CRM_Extension_Browser($this->getRepositoryUrl(), '', $cacheDir); } return $this->browser; } /** * Get the service for loading code from remotely-available extensions * * @return CRM_Extension_Downloader */ public function getDownloader() { if ($this->downloader === NULL) { $basedir = ($this->getDefaultContainer() ? $this->getDefaultContainer()->getBaseDir() : NULL); $this->downloader = new CRM_Extension_Downloader( $this->getManager(), $basedir, CRM_Utils_File::tempdir() // WAS: $config->extensionsDir . DIRECTORY_SEPARATOR . 'tmp'; ); } return $this->downloader; } /** * @return CRM_Utils_Cache_Interface */ public function getCache() { if ($this->cache === NULL) { if (defined('CIVICRM_DSN')) { $cacheGroup = md5(serialize(array('ext', $this->parameters))); $this->cache = new CRM_Utils_Cache_SqlGroup(array( 'group' => $cacheGroup, 'prefetch' => TRUE, )); } else { $this->cache = new CRM_Utils_Cache_ArrayCache(array()); } } return $this->cache; } /** * Determine the URL which provides a feed of available extensions. * * @return string|FALSE */ public function getRepositoryUrl() { if (empty($this->_repoUrl) && $this->_repoUrl !== FALSE) { $config = CRM_Core_Config::singleton(); $url = CRM_Core_BAO_Setting::getItem('Extension Preferences', 'ext_repo_url', NULL, CRM_Extension_Browser::DEFAULT_EXTENSIONS_REPOSITORY); // boolean false means don't try to check extensions // http://issues.civicrm.org/jira/browse/CRM-10575 if ($url === FALSE) { $this->_repoUrl = FALSE; } else { $this->_repoUrl = CRM_Utils_System::evalUrl($url); } } return $this->_repoUrl; } }