Merge branch '5.51'
[civicrm-core.git] / Civi / API / Kernel.php
index 91544231ae8ebd97053d0bd30021a7c070ce192d..96cc6120fc5f025bd31ba85dc70a032e61eff04d 100644 (file)
@@ -86,12 +86,12 @@ class Kernel {
         $this->dispatcher->dispatch('civi.api.exception', new ExceptionEvent($e, NULL, $apiRequest, $this));
       }
 
-      if ($e instanceof \PEAR_Exception) {
-        $err = $this->formatPearException($e, $apiRequest);
-      }
-      elseif ($e instanceof \API_Exception) {
+      if ($e instanceof \API_Exception) {
         $err = $this->formatApiException($e, $apiRequest);
       }
+      elseif ($e instanceof \PEAR_Exception) {
+        $err = $this->formatPearException($e, $apiRequest);
+      }
       else {
         $err = $this->formatException($e, $apiRequest);
       }
@@ -159,12 +159,15 @@ class Kernel {
    */
   public function boot($apiRequest) {
     require_once 'api/Exception.php';
+    // the create error function loads some functions from utils
+    // so this require is also needed for apiv4 until such time as
+    // we alter create error.
+    require_once 'api/v3/utils.php';
     switch ($apiRequest['version']) {
       case 3:
         if (!is_array($apiRequest['params'])) {
           throw new \API_Exception('Input variable `params` is not an array', 2000);
         }
-        require_once 'api/v3/utils.php';
         _civicrm_api3_initialize();
         break;
 
@@ -215,7 +218,7 @@ class Kernel {
    */
   public function authorize($apiProvider, $apiRequest) {
     /** @var \Civi\API\Event\AuthorizeEvent $event */
-    $event = $this->dispatcher->dispatch('civi.api.authorize', new AuthorizeEvent($apiProvider, $apiRequest, $this));
+    $event = $this->dispatcher->dispatch('civi.api.authorize', new AuthorizeEvent($apiProvider, $apiRequest, $this, \CRM_Core_Session::getLoggedInContactID() ?: 0));
     if (!$event->isAuthorized()) {
       throw new \Civi\API\Exception\UnauthorizedException("Authorization failed");
     }