Merge pull request #13232 from JO0st/core-574
[civicrm-core.git] / Civi / API / Provider / MagicFunctionProvider.php
index 1b44dd931a47de62bc32cbccbe5174e709c0a2e1..cdeaab339f8cb15860b81e0052853bc1cf4485e5 100644 (file)
@@ -1,27 +1,11 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 5                                                  |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2019                                |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM.                                    |
- |                                                                    |
- | CiviCRM is free software; you can copy, modify, and distribute it  |
- | under the terms of the GNU Affero General Public License           |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ | Copyright CiviCRM LLC. All rights reserved.                        |
  |                                                                    |
- | CiviCRM is distributed in the hope that it will be useful, but     |
- | WITHOUT ANY WARRANTY; without even the implied warranty of         |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
- | See the GNU Affero General Public License for more details.        |
- |                                                                    |
- | You should have received a copy of the GNU Affero General Public   |
- | License and the CiviCRM Licensing Exception along                  |
- | with this program; if not, contact CiviCRM LLC                     |
- | at info[AT]civicrm[DOT]org. If you have questions about the        |
- | GNU Affero General Public License or the licensing of CiviCRM,     |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ | This work is published under the GNU AGPLv3 license with some      |
+ | permitted exceptions and without any warranty. For full license    |
+ | and copyright information, see https://civicrm.org/licensing       |
  +--------------------------------------------------------------------+
  */
 
@@ -35,15 +19,16 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  * conventions.
  */
 class MagicFunctionProvider implements EventSubscriberInterface, ProviderInterface {
+
   /**
    * @return array
    */
   public static function getSubscribedEvents() {
-    return array(
-      Events::RESOLVE => array(
-        array('onApiResolve', Events::W_MIDDLE),
-      ),
-    );
+    return [
+      Events::RESOLVE => [
+        ['onApiResolve', Events::W_MIDDLE],
+      ],
+    ];
   }
 
   /**
@@ -54,7 +39,7 @@ class MagicFunctionProvider implements EventSubscriberInterface, ProviderInterfa
   /**
    */
   public function __construct() {
-    $this->cache = array();
+    $this->cache = [];
   }
 
   /**
@@ -108,12 +93,12 @@ class MagicFunctionProvider implements EventSubscriberInterface, ProviderInterfa
    * @return array
    */
   public function getEntityNames($version) {
-    $entities = array();
+    $entities = [];
     $include_dirs = array_unique(explode(PATH_SEPARATOR, get_include_path()));
     #$include_dirs = array(dirname(__FILE__). '/../../');
     foreach ($include_dirs as $include_dir) {
       $api_dir = implode(DIRECTORY_SEPARATOR,
-        array($include_dir, 'api', 'v' . $version));
+        [$include_dir, 'api', 'v' . $version]);
       if (!is_dir($api_dir)) {
         continue;
       }
@@ -137,7 +122,7 @@ class MagicFunctionProvider implements EventSubscriberInterface, ProviderInterfa
         }
       }
     }
-    $entities = array_diff($entities, array('Generic'));
+    $entities = array_diff($entities, ['Generic']);
     $entities = array_unique($entities);
     sort($entities);
 
@@ -154,12 +139,12 @@ class MagicFunctionProvider implements EventSubscriberInterface, ProviderInterfa
     $entity = _civicrm_api_get_camel_name($entity);
     $entities = $this->getEntityNames($version);
     if (!in_array($entity, $entities)) {
-      return array();
+      return [];
     }
     $this->loadEntity($entity, $version);
 
     $functions = get_defined_functions();
-    $actions = array();
+    $actions = [];
     $prefix = 'civicrm_api' . $version . '_' . _civicrm_api_get_entity_name_from_camel($entity) . '_';
     $prefixGeneric = 'civicrm_api' . $version . '_generic_';
     foreach ($functions['user'] as $fct) {
@@ -203,21 +188,21 @@ class MagicFunctionProvider implements EventSubscriberInterface, ProviderInterfa
       // someone already loaded the appropriate file
       // FIXME: This has the affect of masking bugs in load order; this is
       // included to provide bug-compatibility.
-      $this->cache[$cachekey] = array('function' => $stdFunction, 'is_generic' => FALSE);
+      $this->cache[$cachekey] = ['function' => $stdFunction, 'is_generic' => FALSE];
       return $this->cache[$cachekey];
     }
 
-    $stdFiles = array(
+    $stdFiles = [
       // By convention, the $camelName.php is more likely to contain the
       // function, so test it first
       'api/v' . $apiRequest['version'] . '/' . $camelName . '.php',
       'api/v' . $apiRequest['version'] . '/' . $camelName . '/' . $actionCamelName . '.php',
-    );
+    ];
     foreach ($stdFiles as $stdFile) {
       if (\CRM_Utils_File::isIncludable($stdFile)) {
         require_once $stdFile;
         if (function_exists($stdFunction)) {
-          $this->cache[$cachekey] = array('function' => $stdFunction, 'is_generic' => FALSE);
+          $this->cache[$cachekey] = ['function' => $stdFunction, 'is_generic' => FALSE];
           return $this->cache[$cachekey];
         }
       }
@@ -227,23 +212,23 @@ class MagicFunctionProvider implements EventSubscriberInterface, ProviderInterfa
     require_once 'api/v3/Generic.php';
     # $genericFunction = 'civicrm_api3_generic_' . $apiRequest['action'];
     $genericFunction = $this->getFunctionName('generic', $apiRequest['action'], $apiRequest['version']);
-    $genericFiles = array(
+    $genericFiles = [
       // By convention, the Generic.php is more likely to contain the
       // function, so test it first
       'api/v' . $apiRequest['version'] . '/Generic.php',
       'api/v' . $apiRequest['version'] . '/Generic/' . $actionCamelName . '.php',
-    );
+    ];
     foreach ($genericFiles as $genericFile) {
       if (\CRM_Utils_File::isIncludable($genericFile)) {
         require_once $genericFile;
         if (function_exists($genericFunction)) {
-          $this->cache[$cachekey] = array('function' => $genericFunction, 'is_generic' => TRUE);
+          $this->cache[$cachekey] = ['function' => $genericFunction, 'is_generic' => TRUE];
           return $this->cache[$cachekey];
         }
       }
     }
 
-    $this->cache[$cachekey] = array('function' => FALSE, 'is_generic' => FALSE);
+    $this->cache[$cachekey] = ['function' => FALSE, 'is_generic' => FALSE];
     return $this->cache[$cachekey];
   }
 
@@ -285,12 +270,13 @@ class MagicFunctionProvider implements EventSubscriberInterface, ProviderInterfa
     }
 
     // Check for standalone action files; to match _civicrm_api_resolve(), only load the first one
-    $loaded_files = array(); // array($relativeFilePath => TRUE)
+    // array($relativeFilePath => TRUE)
+    $loaded_files = [];
     $include_dirs = array_unique(explode(PATH_SEPARATOR, get_include_path()));
     foreach ($include_dirs as $include_dir) {
-      foreach (array($camelName, 'Generic') as $name) {
+      foreach ([$camelName, 'Generic'] as $name) {
         $action_dir = implode(DIRECTORY_SEPARATOR,
-          array($include_dir, 'api', "v${version}", $name));
+          [$include_dir, 'api', "v${version}", $name]);
         if (!is_dir($action_dir)) {
           continue;
         }
@@ -299,7 +285,8 @@ class MagicFunctionProvider implements EventSubscriberInterface, ProviderInterfa
         foreach ($iterator as $fileinfo) {
           $file = $fileinfo->getFilename();
           if (array_key_exists($file, $loaded_files)) {
-            continue; // action provided by an earlier item on include_path
+            // action provided by an earlier item on include_path
+            continue;
           }
 
           $parts = explode(".", $file);