Merge remote-tracking branch 'upstream/4.6' into 4.6-master-2015-04-26-09-47-18
[civicrm-core.git] / CRM / Extension / Mapper.php
index 593429c873a7e727ffb9469ba2c72456a1963128..f765afb7a52a743de5ae727bed002ccbefa7d7c0 100755 (executable)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -23,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  * This class proivdes various helper functions for locating extensions
  * module-extensions.
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
 class CRM_Extension_Mapper {
 
   /**
-   * An URL for public extensions repository
+   * An URL for public extensions repository.
    */
   //const DEFAULT_EXTENSIONS_REPOSITORY = 'http://civicrm.org/extdir/ver={ver}|cms={uf}';
 
   /**
-   * Extension info file name
+   * Extension info file name.
    */
   const EXT_TEMPLATES_DIRNAME = 'templates';
 
@@ -97,15 +97,17 @@ class CRM_Extension_Mapper {
     $this->cacheKey = $cacheKey;
     if ($civicrmUrl) {
       $this->civicrmUrl = rtrim($civicrmUrl, '/');
-    } else {
+    }
+    else {
       $config = CRM_Core_Config::singleton();
       $this->civicrmUrl = rtrim($config->resourceBase, '/');
     }
     if ($civicrmPath) {
-      $this->civicrmPath = rtrim($civicrmPath,'/');
-    } else {
+      $this->civicrmPath = rtrim($civicrmPath, '/');
+    }
+    else {
       global $civicrm_root;
-      $this->civicrmPath = rtrim($civicrm_root,'/');
+      $this->civicrmPath = rtrim($civicrm_root, '/');
     }
   }
 
@@ -116,7 +118,8 @@ class CRM_Extension_Mapper {
    * @param string $clazz
    *   Extension class name.
    *
-   * @return string name of extension key
+   * @return string
+   *   name of extension key
    */
   public function classToKey($clazz) {
     return str_replace('_', '.', $clazz);
@@ -128,7 +131,8 @@ class CRM_Extension_Mapper {
    *
    * @param $clazz
    *
-   * @return string full path the extension .php file
+   * @return string
+   *   full path the extension .php file
    */
   public function classToPath($clazz) {
     $elements = explode('_', $clazz);
@@ -143,7 +147,8 @@ class CRM_Extension_Mapper {
    * @param string $key
    *   A string which might be an extension key.
    *
-   * @return boolean true if given string is an extension name
+   * @return bool
+   *   true if given string is an extension name
    */
   public function isExtensionKey($key) {
     // check if the string is an extension name or the class
@@ -157,7 +162,8 @@ class CRM_Extension_Mapper {
    * @param string $clazz
    *   A string which might be an extension class name.
    *
-   * @return boolean true if given string is an extension class name
+   * @return bool
+   *   true if given string is an extension class name
    */
   public function isExtensionClass($clazz) {
 
@@ -180,7 +186,8 @@ class CRM_Extension_Mapper {
     if ($fresh || !array_key_exists($key, $this->infos)) {
       try {
         $this->infos[$key] = CRM_Extension_Info::loadFromFile($this->container->getPath($key) . DIRECTORY_SEPARATOR . CRM_Extension_Info::FILENAME);
-      } catch (CRM_Extension_Exception $e) {
+      }
+      catch (CRM_Extension_Exception $e) {
         // file has more detailed info, but we'll fallback to DB if it's missing -- DB has enough info to uninstall
         $this->infos[$key] = CRM_Extension_System::singleton()->getManager()->createInfoFromDB($key);
         if (!$this->infos[$key]) {
@@ -198,7 +205,8 @@ class CRM_Extension_Mapper {
    * @param string $key
    *   Extension key.
    *
-   * @return string name of extension's main class
+   * @return string
+   *   name of extension's main class
    */
   public function keyToClass($key) {
     return str_replace('.', '_', $key);
@@ -212,7 +220,8 @@ class CRM_Extension_Mapper {
    * @param string $key
    *   Extension key.
    *
-   * @return string path to file containing extension's main class
+   * @return string
+   *   path to file containing extension's main class
    */
   public function keyToPath($key) {
     $info = $this->keyToInfo($key);
@@ -225,7 +234,8 @@ class CRM_Extension_Mapper {
    *
    * @param string $key
    *   Extension key.
-   * @return string local path of the extension source tree
+   * @return string
+   *   local path of the extension source tree
    */
   public function keyToBasePath($key) {
     if ($key == 'civicrm') {
@@ -242,7 +252,8 @@ class CRM_Extension_Mapper {
    * @param string $key
    *   Extension key.
    *
-   * @return string url for resources in this extension
+   * @return string
+   *   url for resources in this extension
    */
   public function keyToUrl($key) {
     if ($key == 'civicrm') {
@@ -261,9 +272,10 @@ class CRM_Extension_Mapper {
   /**
    * Fetch the list of active extensions of type 'module'
    *
-   * @param $fresh
-   *   Bool whether to forcibly reload extensions list from canonical store.
-   * @return array - array(array('prefix' => $, 'file' => $))
+   * @param bool $fresh
+   *   whether to forcibly reload extensions list from canonical store.
+   * @return array
+   *   array(array('prefix' => $, 'file' => $))
    */
   public function getActiveModuleFiles($fresh = FALSE) {
     $config = CRM_Core_Config::singleton();
@@ -292,7 +304,8 @@ class CRM_Extension_Mapper {
             'prefix' => $dao->file,
             'filePath' => $this->keyToPath($dao->full_name),
           );
-        } catch (CRM_Extension_Exception $e) {
+        }
+        catch (CRM_Extension_Exception $e) {
           // Putting a stub here provides more consistency
           // in how getActiveModuleFiles when racing between
           // dirty file-removals and cache-clears.
@@ -312,9 +325,10 @@ class CRM_Extension_Mapper {
   }
 
   /**
-   * Get a list of base URLs for all active modules
+   * Get a list of base URLs for all active modules.
    *
-   * @return array (string $extKey => string $baseUrl)
+   * @return array
+   *   (string $extKey => string $baseUrl)
    */
   public function getActiveModuleUrls() {
     // TODO optimization/caching
@@ -347,7 +361,8 @@ class CRM_Extension_Mapper {
   /**
    * Get a list of all installed modules, including enabled and disabled ones
    *
-   * @return array CRM_Core_Module
+   * @return array
+   *   CRM_Core_Module
    */
   public function getModules() {
     $result = array();
@@ -367,7 +382,8 @@ class CRM_Extension_Mapper {
    * @param string $clazz
    *   Extension class name.
    *
-   * @return string path to extension's templates directory
+   * @return string
+   *   path to extension's templates directory
    */
   public function getTemplatePath($clazz) {
     $path = $this->container->getPath($this->classToKey($clazz));
@@ -377,7 +393,7 @@ class CRM_Extension_Mapper {
     $pathElm = explode(DIRECTORY_SEPARATOR, $path);
     array_pop($pathElm);
     return implode(DIRECTORY_SEPARATOR, $pathElm) . DIRECTORY_SEPARATOR . self::EXT_TEMPLATES_DIRNAME;
-    */
+     */
   }
 
   /**
@@ -388,7 +404,8 @@ class CRM_Extension_Mapper {
    * @param string $clazz
    *   Extension class name.
    *
-   * @return string extension's template name
+   * @return string
+   *   extension's template name
    */
   public function getTemplateName($clazz) {
     $info = $this->keyToInfo($this->classToKey($clazz));
@@ -402,4 +419,5 @@ class CRM_Extension_Mapper {
       $this->cache->delete($this->cacheKey . '/moduleFiles');
     }
   }
+
 }