Set API Function Name Case To All Lowercase
[civicrm-core.git] / CRM / Extension / Info.php
index 53aff153da9eff09805052f358c4fe385efdeeae..3a68dc69a56f48a762430924d0df332c356fb77e 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2017                                |
+ | Copyright CiviCRM LLC (c) 2004-2018                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -29,7 +29,7 @@
  * Metadata for an extension (e.g. the extension's "info.xml" file)
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2017
+ * @copyright CiviCRM LLC (c) 2004-2018
  */
 class CRM_Extension_Info {
 
@@ -51,6 +51,12 @@ class CRM_Extension_Info {
    */
   public $classloader = array();
 
+  /**
+   * @var array
+   *   Each item is they key-name of an extension required by this extension.
+   */
+  public $requires = array();
+
   /**
    * Load extension info an XML file.
    *
@@ -90,6 +96,27 @@ class CRM_Extension_Info {
     return $instance;
   }
 
+  /**
+   * Build a reverse-dependency map.
+   *
+   * @param array $infos
+   *   The universe of available extensions.
+   *   Ex: $infos['org.civicrm.foobar'] = new CRM_Extension_Info().
+   * @return array
+   *   If "org.civicrm.api" is required by "org.civicrm.foo", then return
+   *   array('org.civicrm.api' => array(CRM_Extension_Info[org.civicrm.foo])).
+   *   Array(string $key => array $requiredBys).
+   */
+  public static function buildReverseMap($infos) {
+    $revMap = array();
+    foreach ($infos as $info) {
+      foreach ($info->requires as $key) {
+        $revMap[$key][] = $info;
+      }
+    }
+    return $revMap;
+  }
+
   /**
    * @param null $key
    * @param null $type
@@ -141,6 +168,12 @@ class CRM_Extension_Info {
           );
         }
       }
+      elseif ($attr === 'requires') {
+        $this->requires = array();
+        foreach ($val->ext as $ext) {
+          $this->requires[] = (string) $ext;
+        }
+      }
       else {
         $this->$attr = CRM_Utils_XML::xmlObjToArray($val);
       }