INFRA-132 - CRM/Core - Misc
[civicrm-core.git] / CRM / Core / Component.php
index c5c49a6a4ffee83ceb4c1c77f71f46e4e326768a..0a7fe2a69c2ff8ee1c6da718af105dee06082e90 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  */
 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;
 
@@ -70,12 +70,12 @@ class CRM_Core_Component {
   }
 
   /**
-   * @param $name
+   * @param string $name
    * @param null $attribute
    *
    * @return mixed
    */
-  static function get($name, $attribute = NULL) {
+  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);
@@ -99,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}).");
@@ -151,7 +151,7 @@ class CRM_Core_Component {
    *
    * @return bool
    */
-  static function invoke(&$args, $type) {
+  public static function invoke(&$args, $type) {
     $info = self::_info();
     $config = CRM_Core_Config::singleton();
 
@@ -186,7 +186,7 @@ class CRM_Core_Component {
   /**
    * @return array
    */
-  static function xmlMenu() {
+  public static function xmlMenu() {
 
     // lets build the menu for all components
     $info = self::getComponents(TRUE);
@@ -204,7 +204,7 @@ class CRM_Core_Component {
   /**
    * @return array
    */
-  static function &menu() {
+  public static function &menu() {
     $info = self::_info();
     $items = array();
     foreach ($info as $name => $comp) {
@@ -223,7 +223,7 @@ class CRM_Core_Component {
    * @param $config
    * @param bool $oldMode
    */
-  static function addConfig(&$config, $oldMode = FALSE) {
+  public static function addConfig(&$config, $oldMode = FALSE) {
     $info = self::_info();
 
     foreach ($info as $name => $comp) {
@@ -234,22 +234,26 @@ class CRM_Core_Component {
   }
 
   /**
-   * @param $componentName
+   * @param string $componentName
    *
    * @return mixed
    */
-  static function getComponentID($componentName) {
+  public static function getComponentID($componentName) {
     $info = self::_info();
-
-    return $info[$componentName]->componentID;
+    if (!empty($info[$componentName])) {
+      return $info[$componentName]->componentID;
+    }
+    else {
+      return;
+    }
   }
 
   /**
-   * @param $componentID
+   * @param int $componentID
    *
    * @return int|null|string
    */
-  static function getComponentName($componentID) {
+  public static function getComponentName($componentID) {
     $info = self::_info();
 
     $componentName = NULL;
@@ -266,7 +270,7 @@ class CRM_Core_Component {
   /**
    * @return array
    */
-  static function &getQueryFields() {
+  public static function &getQueryFields() {
     $info = self::_info();
     $fields = array();
     foreach ($info as $name => $comp) {
@@ -281,9 +285,9 @@ class CRM_Core_Component {
 
   /**
    * @param $query
-   * @param $fnName
+   * @param string $fnName
    */
-  static function alterQuery(&$query, $fnName) {
+  public static function alterQuery(&$query, $fnName) {
     $info = self::_info();
 
     foreach ($info as $name => $comp) {
@@ -295,13 +299,13 @@ class CRM_Core_Component {
   }
 
   /**
-   * @param $fieldName
+   * @param string $fieldName
    * @param $mode
    * @param $side
    *
    * @return null
    */
-  static function from($fieldName, $mode, $side) {
+  public static function from($fieldName, $mode, $side) {
     $info = self::_info();
 
     $from = NULL;
@@ -323,7 +327,8 @@ class CRM_Core_Component {
    *
    * @return null
    */
-  static function &defaultReturnProperties($mode,
+  static function &defaultReturnProperties(
+    $mode,
     $includeCustomFields = TRUE
   ) {
     $info = self::_info();
@@ -342,9 +347,9 @@ class CRM_Core_Component {
   }
 
   /**
-   * @param $form
+   * @param CRM_Core_Form $form
    */
-  static function &buildSearchForm(&$form) {
+  public static function &buildSearchForm(&$form) {
     $info = self::_info();
 
     foreach ($info as $name => $comp) {
@@ -357,9 +362,9 @@ class CRM_Core_Component {
 
   /**
    * @param $row
-   * @param $id
+   * @param int $id
    */
-  static function searchAction(&$row, $id) {
+  public static function searchAction(&$row, $id) {
     $info = self::_info();
 
     foreach ($info as $name => $comp) {
@@ -373,7 +378,7 @@ class CRM_Core_Component {
   /**
    * @return array|null
    */
-  static function &contactSubTypes() {
+  public static function &contactSubTypes() {
     if (self::$_contactSubTypes == NULL) {
       self::$_contactSubTypes = array();
     }
@@ -387,7 +392,7 @@ class CRM_Core_Component {
    *
    * @return null
    */
-  static function &contactSubTypeProperties($subType, $op) {
+  public static function &contactSubTypeProperties($subType, $op) {
     $properties = self::contactSubTypes();
     if (array_key_exists($subType, $properties) &&
       array_key_exists($op, $properties[$subType])
@@ -400,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();
@@ -413,15 +418,15 @@ 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) {
@@ -433,14 +438,13 @@ 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') {
@@ -450,7 +454,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);
@@ -461,4 +465,3 @@ class CRM_Core_Component {
     return $components;
   }
 }
-