Merge pull request #14987 from civicrm/5.16
[civicrm-core.git] / Civi / API / Subscriber / DynamicFKAuthorization.php
index daddd72af9373d3f71016b4d64549800092ffa94..94398ac0caa9cc53d859acb255b81ea8512fa04e 100644 (file)
@@ -51,11 +51,11 @@ class DynamicFKAuthorization implements EventSubscriberInterface {
    * @return array
    */
   public static function getSubscribedEvents() {
-    return array(
-      Events::AUTHORIZE => array(
-        array('onApiAuthorize', Events::W_EARLY),
-      ),
-    );
+    return [
+      Events::AUTHORIZE => [
+        ['onApiAuthorize', Events::W_EARLY],
+      ],
+    ];
   }
 
   /**
@@ -146,7 +146,7 @@ class DynamicFKAuthorization implements EventSubscriberInterface {
     $apiRequest = $event->getApiRequest();
     if ($apiRequest['version'] == 3 && \CRM_Utils_String::convertStringToCamel($apiRequest['entity']) == $this->entityName && in_array(strtolower($apiRequest['action']), $this->actions)) {
       if (isset($apiRequest['params']['field_name'])) {
-        $fldIdx = \CRM_Utils_Array::index(array('field_name'), $this->getCustomFields());
+        $fldIdx = \CRM_Utils_Array::index(['field_name'], $this->getCustomFields());
         if (empty($fldIdx[$apiRequest['params']['field_name']])) {
           throw new \Exception("Failed to map custom field to entity table");
         }
@@ -200,7 +200,7 @@ class DynamicFKAuthorization implements EventSubscriberInterface {
    *   The API action (e.g. "create").
    * @param string $entityTable
    *   The target entity table (e.g. "civicrm_mailing").
-   * @param int|NULL $entityId
+   * @param int|null $entityId
    *   The target entity ID.
    * @param array $apiRequest
    *   The full API request.
@@ -227,19 +227,20 @@ class DynamicFKAuthorization implements EventSubscriberInterface {
     $exception = NULL;
     $self = $this;
     \CRM_Core_Transaction::create(TRUE)->run(function($tx) use ($entity, $action, $entityId, &$exception, $self) {
-      $tx->rollback(); // Just to be safe.
+      // Just to be safe.
+      $tx->rollback();
 
-      $params = array(
+      $params = [
         'version' => 3,
         'check_permissions' => 1,
         'id' => $entityId,
-      );
+      ];
 
       $result = $self->kernel->run($entity, $self->getDelegatedAction($action), $params);
       if ($result['is_error'] || empty($result['values'])) {
-        $exception = new \Civi\API\Exception\UnauthorizedException("Authorization failed on ($entity,$entityId)", array(
+        $exception = new \Civi\API\Exception\UnauthorizedException("Authorization failed on ($entity,$entityId)", [
           'cause' => $result,
-        ));
+        ]);
       }
     });
 
@@ -325,25 +326,25 @@ class DynamicFKAuthorization implements EventSubscriberInterface {
    * @throws \Exception
    */
   public function getDelegate($id) {
-    $query = \CRM_Core_DAO::executeQuery($this->lookupDelegateSql, array(
-      1 => array($id, 'Positive'),
-    ));
+    $query = \CRM_Core_DAO::executeQuery($this->lookupDelegateSql, [
+      1 => [$id, 'Positive'],
+    ]);
     if ($query->fetch()) {
       if (!preg_match('/^civicrm_value_/', $query->entity_table)) {
         // A normal attachment directly on its entity.
-        return array($query->is_valid, $query->entity_table, $query->entity_id);
+        return [$query->is_valid, $query->entity_table, $query->entity_id];
       }
 
       // Ex: Translate custom-field table ("civicrm_value_foo_4") to
       // entity table ("civicrm_activity").
-      $tblIdx = \CRM_Utils_Array::index(array('table_name'), $this->getCustomFields());
+      $tblIdx = \CRM_Utils_Array::index(['table_name'], $this->getCustomFields());
       if (isset($tblIdx[$query->entity_table])) {
-        return array($query->is_valid, $tblIdx[$query->entity_table]['entity_table'], $query->entity_id);
+        return [$query->is_valid, $tblIdx[$query->entity_table]['entity_table'], $query->entity_id];
       }
       throw new \Exception('Failed to lookup entity table for custom field.');
     }
     else {
-      return array(FALSE, NULL, NULL);
+      return [FALSE, NULL, NULL];
     }
   }
 
@@ -363,14 +364,14 @@ class DynamicFKAuthorization implements EventSubscriberInterface {
    */
   public function getCustomFields() {
     $query = \CRM_Core_DAO::executeQuery($this->lookupCustomFieldSql);
-    $rows = array();
+    $rows = [];
     while ($query->fetch()) {
-      $rows[] = array(
+      $rows[] = [
         'field_name' => $query->field_name,
         'table_name' => $query->table_name,
         'extends' => $query->extends,
         'entity_table' => \CRM_Core_BAO_CustomGroup::getTableNameByEntityName($query->extends),
-      );
+      ];
     }
     return $rows;
   }