From: Tim Otten Date: Mon, 29 Dec 2014 02:49:16 +0000 (-0800) Subject: CRM/Extension - Code style X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=78612209433387c532f281bb26185aaded8b157a;p=civicrm-core.git CRM/Extension - Code style --- diff --git a/CRM/Extension/Browser.php b/CRM/Extension/Browser.php index 8bc30d31ef..4171112a18 100644 --- a/CRM/Extension/Browser.php +++ b/CRM/Extension/Browser.php @@ -42,15 +42,18 @@ class CRM_Extension_Browser { const DEFAULT_EXTENSIONS_REPOSITORY = 'https://civicrm.org/extdir/ver={ver}|cms={uf}'; /** - * @param string $repoUrl URL of the remote repository - * @param string $indexPath relative path of the 'index' file within the repository - * @param string $cacheDir local path in which to cache files + * @param string $repoUrl + * URL of the remote repository. + * @param string $indexPath + * Relative path of the 'index' file within the repository. + * @param string $cacheDir + * Local path in which to cache files. */ public function __construct($repoUrl, $indexPath, $cacheDir) { $this->repoUrl = $repoUrl; $this->cacheDir = $cacheDir; $this->indexPath = $indexPath; - if ($cacheDir && !file_exists($cacheDir) && is_dir(dirname($cacheDir)) && is_writeable(dirname($cacheDir))) { + if ($cacheDir && !file_exists($cacheDir) && is_dir(dirname($cacheDir)) && is_writable(dirname($cacheDir))) { CRM_Utils_File::createDir($cacheDir, FALSE); } } @@ -74,6 +77,9 @@ class CRM_Extension_Browser { return $this->repoUrl; } + /** + * Refresh the cache of remotely-available extensions. + */ public function refresh() { $file = $this->getTsPath(); if (file_exists($file)) { @@ -84,7 +90,8 @@ class CRM_Extension_Browser { /** * Determine whether downloading is supported * - * @return array list of error messages; empty if OK + * @return array + * List of error messages; empty if OK. */ public function checkRequirements() { if (!$this->isEnabled()) { @@ -93,7 +100,7 @@ class CRM_Extension_Browser { $errors = array(); - if (!$this->cacheDir || !is_dir($this->cacheDir) || !is_writeable($this->cacheDir)) { + if (!$this->cacheDir || !is_dir($this->cacheDir) || !is_writable($this->cacheDir)) { $civicrmDestination = urlencode(CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1')); $url = CRM_Utils_System::url('civicrm/admin/setting/path', "reset=1&civicrmDestination=${civicrmDestination}"); $errors[] = array( @@ -103,7 +110,7 @@ class CRM_Extension_Browser { 1 => $this->cacheDir, 2 => $url, ) - ) + ), ); } @@ -113,7 +120,8 @@ class CRM_Extension_Browser { /** * Get a list of all available extensions * - * @return array ($key => CRM_Extension_Info) + * @return array + * ($key => CRM_Extension_Info) */ public function getExtensions() { if (!$this->isEnabled() || count($this->checkRequirements())) { @@ -135,7 +143,8 @@ class CRM_Extension_Browser { /** * Get a description of a particular extension * - * @param $key + * @param string $key + * Fully-qualified extension name. * * @return CRM_Extension_Info|NULL */ @@ -144,7 +153,8 @@ class CRM_Extension_Browser { $exts = $this->getExtensions(); if (array_key_exists($key, $exts)) { return $exts[$key]; - } else { + } + else { // throw new CRM_Extension_Exception("Unknown remote extension: $key"); return NULL; } @@ -155,7 +165,7 @@ class CRM_Extension_Browser { * @throws CRM_Extension_Exception_ParseException */ private function _discoverRemote() { - $tsPath = $this->getTsPath(); + $tsPath = $this->getTsPath(); $timestamp = FALSE; if (file_exists($tsPath)) { @@ -194,9 +204,9 @@ class CRM_Extension_Browser { * @return array */ private function grabCachedKeyList() { - $result = array(); + $result = array(); $cachedPath = $this->cacheDir . DIRECTORY_SEPARATOR; - $files = scandir($cachedPath); + $files = scandir($cachedPath); foreach ($files as $dc => $fname) { if (substr($fname, -4) == '.xml') { $result[] = array('key' => substr($fname, 0, -4)); @@ -222,7 +232,7 @@ class CRM_Extension_Browser { ini_set('allow_url_fopen', 1); } - if(FALSE === $this->getRepositoryUrl()) { + if (FALSE === $this->getRepositoryUrl()) { // don't check if the user has configured civi not to check an external // url for extensions. See CRM-10575. CRM_Core_Session::setStatus(ts('Not checking remote URL for extensions since ext_repo_url is set to false.'), ts('Check Settings'), 'alert'); @@ -233,7 +243,8 @@ class CRM_Extension_Browser { list ($status, $extdir) = CRM_Utils_HttpClient::singleton()->get($this->getRepositoryUrl() . $this->indexPath); if ($extdir === FALSE || $status !== CRM_Utils_HttpClient::STATUS_OK) { CRM_Core_Session::setStatus(ts('The CiviCRM public extensions directory at %1 could not be contacted - please check your webserver can make external HTTP requests or contact CiviCRM team on CiviCRM forum.
', array(1 => $this->getRepositoryUrl())), ts('Connection Error'), 'error'); - } else { + } + else { $lines = explode("\n", $extdir); foreach ($lines as $ln) { @@ -251,7 +262,11 @@ class CRM_Extension_Browser { // CRM-13141 There may not be any compatible extensions available for the requested CiviCRM version + CMS. If so, $extdir is empty so just return a notification. if (empty($exts)) { $config = CRM_Core_Config::singleton(); - CRM_Core_Session::setStatus(ts('There are currently no extensions on the CiviCRM public extension directory which are compatible with version %2 (requested extensions from here). If you want to install an extension which is not marked as compatible, you may be able to download and install extensions manually (depending on access to your web server).
', array(1 => $this->getRepositoryUrl(), 2 => $config->civiVersion, 3 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Extensions')), ts('No Extensions Available for this Version'), 'info'); + CRM_Core_Session::setStatus(ts('There are currently no extensions on the CiviCRM public extension directory which are compatible with version %2 (requested extensions from here). If you want to install an extension which is not marked as compatible, you may be able to download and install extensions manually (depending on access to your web server).
', array( + 1 => $this->getRepositoryUrl(), + 2 => $config->civiVersion, + 3 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Extensions', + )), ts('No Extensions Available for this Version'), 'info'); } ini_restore('allow_url_fopen'); @@ -266,16 +281,17 @@ class CRM_Extension_Browser { * Given the key, retrieves the info XML from a remote server * and stores locally, returning the contents. * - * @access public + * @param string $key + * Extension key. + * @param bool $cached + * Whether to use cached data. * - * @param string $key extension key - * @param boolean $cached whether to use cached data - * - * @return contents of info.xml, or null if info.xml cannot be retrieved or parsed + * @return string + * Contents of info.xml, or null if info.xml cannot be retrieved or parsed. */ private function grabRemoteInfoFile($key, $cached = FALSE) { $filename = $this->cacheDir . DIRECTORY_SEPARATOR . $key . '.xml'; - $url = $this->getRepositoryUrl() . '/' . $key . '.xml'; + $url = $this->getRepositoryUrl() . '/' . $key . '.xml'; if (!$cached || !file_exists($filename)) { $fetchStatus = CRM_Utils_HttpClient::singleton()->fetch($url, $filename); @@ -305,14 +321,13 @@ class CRM_Extension_Browser { * @return string */ private function getTsPath() { - return $this->cacheDir . DIRECTORY_SEPARATOR . 'timestamp.txt'; + return $this->cacheDir . DIRECTORY_SEPARATOR . 'timestamp.txt'; } /** * A dummy function required for suppressing download errors */ public static function downloadError($errorNumber, $errorString) { - return; } } diff --git a/CRM/Extension/Container/Basic.php b/CRM/Extension/Container/Basic.php index f6c526ff0d..f09753cb96 100644 --- a/CRM/Extension/Container/Basic.php +++ b/CRM/Extension/Container/Basic.php @@ -84,10 +84,14 @@ class CRM_Extension_Container_Basic implements CRM_Extension_Container_Interface public $relUrls = FALSE; /** - * @param string $baseDir local path to the container - * @param string $baseUrl public URL of the container + * @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 + * Cache in which to store extension metadata. + * @param string $cacheKey + * Unique name for this container. */ public function __construct($baseDir, $baseUrl, CRM_Utils_Cache_Interface $cache = NULL, $cacheKey = NULL) { $this->cache = $cache; @@ -136,7 +140,7 @@ class CRM_Extension_Container_Basic implements CRM_Extension_Container_Interface * {@inheritdoc} */ public function getResUrl($key) { - if (! $this->baseUrl) { + if (!$this->baseUrl) { CRM_Core_Session::setStatus( ts('Failed to determine URL for extension (%1). Please update Resource URLs.', array( @@ -169,7 +173,8 @@ class CRM_Extension_Container_Basic implements CRM_Extension_Container_Interface /** * Determine the relative path of an extension directory * - * @param $key + * @param string $key + * Extension name. * * @throws CRM_Extension_Exception_MissingException * @return string @@ -185,7 +190,8 @@ class CRM_Extension_Container_Basic implements CRM_Extension_Container_Interface /** * Scan $basedir for a list of extension-keys * - * @return array($key => $relPath) + * @return array + * ($key => $relPath) */ protected function getRelPaths() { if (!is_array($this->relPaths)) { @@ -199,7 +205,8 @@ class CRM_Extension_Container_Basic implements CRM_Extension_Container_Interface $relPath = CRM_Utils_File::relativize(dirname($infoPath), $this->baseDir); try { $info = CRM_Extension_Info::loadFromFile($infoPath); - } catch (CRM_Extension_Exception_ParseException $e) { + } + catch (CRM_Extension_Exception_ParseException $e) { CRM_Core_Session::setStatus(ts('Parse error in extension: %1', array( 1 => $e->getMessage(), )), '', 'error'); @@ -219,7 +226,8 @@ class CRM_Extension_Container_Basic implements CRM_Extension_Container_Interface /** * Determine the relative path of an extension directory * - * @param $key + * @param string $key + * Extension name. * * @throws CRM_Extension_Exception_MissingException * @return string @@ -235,7 +243,8 @@ class CRM_Extension_Container_Basic implements CRM_Extension_Container_Interface /** * Scan $basedir for a list of extension-keys * - * @return array($key => $relUrl) + * @return array + * ($key => $relUrl) */ protected function getRelUrls() { if (DIRECTORY_SEPARATOR == '/') { @@ -253,8 +262,11 @@ class CRM_Extension_Container_Basic implements CRM_Extension_Container_Interface * Note: Treat as private. This is only public to facilitate testing. * * @param string $dirSep - * @param array $relPaths ($key => $relPath) - * @return array($key => $relUrl) + * Directory separator ("/" or "\"). + * @param array $relPaths + * Array($key => $relPath). + * @return array + * Array($key => $relUrl). */ public static function convertPathsToUrls($dirSep, $relPaths) { $relUrls = array(); diff --git a/CRM/Extension/Container/Collection.php b/CRM/Extension/Container/Collection.php index ae4e3ae353..815789e23a 100644 --- a/CRM/Extension/Container/Collection.php +++ b/CRM/Extension/Container/Collection.php @@ -66,9 +66,13 @@ class CRM_Extension_Container_Collection implements CRM_Extension_Container_Inte public $k2c; /** - * @param array $containers array($name => CRM_Extension_Container_Interface) in order from highest priority (winners) to lowest priority (losers) + * @param array $containers + * Array($name => CRM_Extension_Container_Interface) in order from highest + * priority (winners) to lowest priority (losers). * @param CRM_Utils_Cache_Interface $cache - * @param string $cacheKey unique name for this container + * Cache in which to store extension metadata. + * @param string $cacheKey + * Unique name for this container. */ public function __construct($containers, CRM_Utils_Cache_Interface $cache = NULL, $cacheKey = NULL) { $this->containers = $containers; @@ -124,7 +128,8 @@ class CRM_Extension_Container_Collection implements CRM_Extension_Container_Inte /** * Get the container which defines a particular key * - * @param $key + * @param string $key + * Extension name. * * @throws CRM_Extension_Exception_MissingException * @return CRM_Extension_Container_Interface @@ -133,7 +138,8 @@ class CRM_Extension_Container_Collection implements CRM_Extension_Container_Inte $k2c = $this->getKeysToContainer(); if (isset($k2c[$key]) && isset($this->containers[$k2c[$key]])) { return $this->containers[$k2c[$key]]; - } else { + } + else { throw new CRM_Extension_Exception_MissingException("Unknown extension: $key"); } } diff --git a/CRM/Extension/Container/Default.php b/CRM/Extension/Container/Default.php index 447197c95d..ac620bbc39 100644 --- a/CRM/Extension/Container/Default.php +++ b/CRM/Extension/Container/Default.php @@ -1,8 +1,8 @@ baseDir) || !is_dir($this->baseDir)) { $civicrmDestination = urlencode(CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1')); $url = CRM_Utils_System::url('civicrm/admin/setting/path', "reset=1&civicrmDestination=${civicrmDestination}"); @@ -23,7 +23,7 @@ class CRM_Extension_Container_Default extends CRM_Extension_Container_Basic { array( 1 => $url, ) - ) + ), ); } if (empty($this->baseUrl)) { @@ -35,10 +35,10 @@ class CRM_Extension_Container_Default extends CRM_Extension_Container_Basic { array( 1 => $url, ) - ) + ), ); } return $errors; } -} \ No newline at end of file +} diff --git a/CRM/Extension/Container/Interface.php b/CRM/Extension/Container/Interface.php index e39a038212..d57298028d 100644 --- a/CRM/Extension/Container/Interface.php +++ b/CRM/Extension/Container/Interface.php @@ -40,22 +40,26 @@ interface CRM_Extension_Container_Interface { /** * Determine if any unmet requirements prevent use of this container. * - * @return array list of error messages; empty if OK + * @return array + * List of error messages; empty if OK. */ public function checkRequirements(); /** * Get a list of extensions available in this container * - * @return array list of keys (strings) + * @return array + * List of keys (strings). */ public function getKeys(); /** * Determine the main .php file for an extension * - * @param string $key fully-qualified extension name - * @return string local path to the extension's main .php file + * @param string $key + * Fully-qualified extension name. + * @return string + * Local path to the extension's main .php file. * @throws Exception */ public function getPath($key); @@ -63,11 +67,16 @@ interface CRM_Extension_Container_Interface { /** * Determine the base URL for resources provided by the extension * - * @param string $key fully-qualified extension name - * @return string public URL + * @param string $key + * Fully-qualified extension name. + * @return string + * Public URL. * @throws Exception */ public function getResUrl($key); + /** + * Scan the container for available extensions. + */ public function refresh(); } diff --git a/CRM/Extension/Container/Static.php b/CRM/Extension/Container/Static.php index 642f60dec3..82cfb64d48 100644 --- a/CRM/Extension/Container/Static.php +++ b/CRM/Extension/Container/Static.php @@ -37,7 +37,8 @@ */ class CRM_Extension_Container_Static implements CRM_Extension_Container_Interface { /** - * @param $exts + * @param array $exts + * Array(string $key => array $spec) List of extensions. */ public function __construct($exts) { $this->exts = $exts; @@ -87,14 +88,16 @@ class CRM_Extension_Container_Static implements CRM_Extension_Container_Interfac } /** - * @param $key + * @param string $key + * Extension name. * * @throws CRM_Extension_Exception_MissingException */ protected function getExt($key) { if (isset($this->exts[$key])) { return $this->exts[$key]; - } else { + } + else { throw new CRM_Extension_Exception_MissingException("Missing extension: $key"); } }