CRM-15735 fix - Update payment status for pay-later membership renewal ignores Receiv...
[civicrm-core.git] / CRM / Core / Component.php
index 9c76095969f50500f0e620f1c8bf5ccbfaf0bf65..85c69308675466cdbdfeec609a8ae5ea497de122 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  * Component stores all the static and dynamic information of the various
  * CiviCRM components
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
 class CRM_Core_Component {
 
-  /*
-     * End part (filename) of the component information class'es name
-     * that needs to be present in components main directory.
-     */
-  CONST COMPONENT_INFO_CLASS = 'Info';
+  /**
+   * End part (filename) of the component information class'es name
+   * that needs to be present in components main directory.
+   */
+  const COMPONENT_INFO_CLASS = 'Info';
 
   private static $_info = NULL;
 
   static $_contactSubTypes = NULL;
 
+  /**
+   * @param bool $force
+   *
+   * @return array|null
+   */
   private static function &_info($force = FALSE) {
     if (self::$_info == NULL || $force) {
       self::$_info = array();
@@ -64,7 +69,13 @@ class CRM_Core_Component {
     return self::$_info;
   }
 
-  static function get($name, $attribute = NULL) {
+  /**
+   * @param string $name
+   * @param null $attribute
+   *
+   * @return mixed
+   */
+  public static function get($name, $attribute = NULL) {
     $comp = CRM_Utils_Array::value($name, self::_info());
     if ($attribute) {
       return CRM_Utils_Array::value($attribute, $comp->info);
@@ -72,6 +83,12 @@ class CRM_Core_Component {
     return $comp;
   }
 
+  /**
+   * @param bool $force
+   *
+   * @return array
+   * @throws Exception
+   */
   public static function &getComponents($force = FALSE) {
     static $_cache = NULL;
 
@@ -82,7 +99,7 @@ class CRM_Core_Component {
       $cr->find(FALSE);
       while ($cr->fetch()) {
         $infoClass = $cr->namespace . '_' . self::COMPONENT_INFO_CLASS;
-        require_once (str_replace('_', DIRECTORY_SEPARATOR, $infoClass) . '.php');
+        require_once str_replace('_', DIRECTORY_SEPARATOR, $infoClass) . '.php';
         $infoObject = new $infoClass($cr->name, $cr->namespace, $cr->id);
         if ($infoObject->info['name'] !== $cr->name) {
           CRM_Core_Error::fatal("There is a discrepancy between name in component registry and in info file ({$cr->name}).");
@@ -95,6 +112,11 @@ class CRM_Core_Component {
     return $_cache;
   }
 
+  /**
+   * @param bool $force
+   *
+   * @return array|null
+   */
   static public function &getEnabledComponents($force = FALSE) {
     return self::_info($force);
   }
@@ -103,6 +125,11 @@ class CRM_Core_Component {
     self::getEnabledComponents(TRUE);
   }
 
+  /**
+   * @param bool $translated
+   *
+   * @return array
+   */
   public static function &getNames($translated = FALSE) {
     $allComponents = self::getComponents();
 
@@ -118,7 +145,13 @@ class CRM_Core_Component {
     return $names;
   }
 
-  static function invoke(&$args, $type) {
+  /**
+   * @param $args
+   * @param $type
+   *
+   * @return bool
+   */
+  public static function invoke(&$args, $type) {
     $info = self::_info();
     $config = CRM_Core_Config::singleton();
 
@@ -150,7 +183,10 @@ class CRM_Core_Component {
     return FALSE;
   }
 
-  static function xmlMenu() {
+  /**
+   * @return array
+   */
+  public static function xmlMenu() {
 
     // lets build the menu for all components
     $info = self::getComponents(TRUE);
@@ -165,7 +201,10 @@ class CRM_Core_Component {
     return $files;
   }
 
-  static function &menu() {
+  /**
+   * @return array
+   */
+  public static function &menu() {
     $info = self::_info();
     $items = array();
     foreach ($info as $name => $comp) {
@@ -180,23 +219,41 @@ class CRM_Core_Component {
     return $items;
   }
 
-  static function addConfig(&$config, $oldMode = FALSE) {
+  /**
+   * @param $config
+   * @param bool $oldMode
+   */
+  public static function addConfig(&$config, $oldMode = FALSE) {
     $info = self::_info();
 
     foreach ($info as $name => $comp) {
       $cfg = $comp->getConfigObject();
       $cfg->add($config, $oldMode);
     }
-    return;
+    return NULL;
   }
 
-  static function getComponentID($componentName) {
+  /**
+   * @param string $componentName
+   *
+   * @return mixed
+   */
+  public static function getComponentID($componentName) {
     $info = self::_info();
-
-    return $info[$componentName]->componentID;
+    if (!empty($info[$componentName])) {
+      return $info[$componentName]->componentID;
+    }
+    else {
+      return;
+    }
   }
 
-  static function getComponentName($componentID) {
+  /**
+   * @param int $componentID
+   *
+   * @return int|null|string
+   */
+  public static function getComponentName($componentID) {
     $info = self::_info();
 
     $componentName = NULL;
@@ -210,20 +267,27 @@ class CRM_Core_Component {
     return $componentName;
   }
 
-  static function &getQueryFields() {
+  /**
+   * @return array
+   */
+  public static function &getQueryFields() {
     $info = self::_info();
     $fields = array();
     foreach ($info as $name => $comp) {
       if ($comp->usesSearch()) {
-        $bqr    = $comp->getBAOQueryObject();
-        $flds   = $bqr->getFields();
+        $bqr = $comp->getBAOQueryObject();
+        $flds = $bqr->getFields();
         $fields = array_merge($fields, $flds);
       }
     }
     return $fields;
   }
 
-  static function alterQuery(&$query, $fnName) {
+  /**
+   * @param $query
+   * @param string $fnName
+   */
+  public static function alterQuery(&$query, $fnName) {
     $info = self::_info();
 
     foreach ($info as $name => $comp) {
@@ -234,7 +298,14 @@ class CRM_Core_Component {
     }
   }
 
-  static function from($fieldName, $mode, $side) {
+  /**
+   * @param string $fieldName
+   * @param $mode
+   * @param $side
+   *
+   * @return null
+   */
+  public static function from($fieldName, $mode, $side) {
     $info = self::_info();
 
     $from = NULL;
@@ -250,7 +321,14 @@ class CRM_Core_Component {
     return $from;
   }
 
-  static function &defaultReturnProperties($mode,
+  /**
+   * @param $mode
+   * @param bool $includeCustomFields
+   *
+   * @return null
+   */
+  public static function &defaultReturnProperties(
+    $mode,
     $includeCustomFields = TRUE
   ) {
     $info = self::_info();
@@ -268,7 +346,10 @@ class CRM_Core_Component {
     return $properties;
   }
 
-  static function &buildSearchForm(&$form) {
+  /**
+   * @param CRM_Core_Form $form
+   */
+  public static function &buildSearchForm(&$form) {
     $info = self::_info();
 
     foreach ($info as $name => $comp) {
@@ -279,7 +360,11 @@ class CRM_Core_Component {
     }
   }
 
-  static function searchAction(&$row, $id) {
+  /**
+   * @param $row
+   * @param int $id
+   */
+  public static function searchAction(&$row, $id) {
     $info = self::_info();
 
     foreach ($info as $name => $comp) {
@@ -290,7 +375,10 @@ class CRM_Core_Component {
     }
   }
 
-  static function &contactSubTypes() {
+  /**
+   * @return array|null
+   */
+  public static function &contactSubTypes() {
     if (self::$_contactSubTypes == NULL) {
       self::$_contactSubTypes = array();
     }
@@ -298,7 +386,13 @@ class CRM_Core_Component {
   }
 
 
-  static function &contactSubTypeProperties($subType, $op) {
+  /**
+   * @param $subType
+   * @param $op
+   *
+   * @return null
+   */
+  public static function &contactSubTypeProperties($subType, $op) {
     $properties = self::contactSubTypes();
     if (array_key_exists($subType, $properties) &&
       array_key_exists($op, $properties[$subType])
@@ -311,7 +405,7 @@ class CRM_Core_Component {
   /**
    * FIXME: This function does not appear to do anything. The is_array() check runs on a bunch of objects and (always?) returns false
    */
-  static function &taskList() {
+  public static function &taskList() {
     $info = self::_info();
 
     $tasks = array();
@@ -324,15 +418,13 @@ class CRM_Core_Component {
   }
 
   /**
-   * Function to handle table dependencies of components
+   * Handle table dependencies of components
    *
-   * @param array $tables  array of tables
+   * @param array $tables
+   *   Array of tables.
    *
-   * @return null
-   * @access public
-   * @static
    */
-  static function tableNames(&$tables) {
+  public static function tableNames(&$tables) {
     $info = self::_info();
 
     foreach ($info as $name => $comp) {
@@ -344,14 +436,12 @@ class CRM_Core_Component {
   }
 
   /**
-   * Function to get components info from info file
-   *
+   * Get components info from info file
    */
-  static function getComponentsFromFile($crmFolderDir) {
+  public static function getComponentsFromFile($crmFolderDir) {
     $components = array();
     //traverse CRM folder and check for Info file
-    if (is_dir($crmFolderDir)) {
-      $dir = opendir($crmFolderDir);
+    if (is_dir($crmFolderDir) && $dir = opendir($crmFolderDir)) {
       while ($subDir = readdir($dir)) {
         // skip the extensions diretory since it has an Info.php file also
         if ($subDir == 'Extension') {
@@ -361,7 +451,7 @@ class CRM_Core_Component {
         $infoFile = $crmFolderDir . "/{$subDir}/" . self::COMPONENT_INFO_CLASS . '.php';
         if (file_exists($infoFile)) {
           $infoClass = 'CRM_' . $subDir . '_' . self::COMPONENT_INFO_CLASS;
-          require_once (str_replace('_', DIRECTORY_SEPARATOR, $infoClass) . '.php');
+          require_once str_replace('_', DIRECTORY_SEPARATOR, $infoClass) . '.php';
           $infoObject = new $infoClass(NULL, NULL, NULL);
           $components[$infoObject->info['name']] = $infoObject;
           unset($infoObject);
@@ -371,5 +461,5 @@ class CRM_Core_Component {
 
     return $components;
   }
-}
 
+}