From f6f677e4b798a162b85e13d31e544b832aff003d Mon Sep 17 00:00:00 2001
From: Cornelius <cornelius.amzar@bsz-bw.de>
Date: Fri, 15 Jun 2018 15:13:15 +0200
Subject: [PATCH] Clean up EDS namespacing and exception handling (#1206)

---
 .../EDS/{Exception.php => ApiException.php}       |  8 +++++---
 .../src/VuFindSearch/Backend/EDS/Backend.php      | 15 +++++----------
 .../src/VuFindSearch/Backend/EDS/Base.php         | 15 +++++++--------
 .../src/VuFindSearch/Backend/EDS/Zend2.php        |  8 ++++----
 4 files changed, 21 insertions(+), 25 deletions(-)
 rename module/VuFindSearch/src/VuFindSearch/Backend/EDS/{Exception.php => ApiException.php} (94%)

diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/EDS/Exception.php b/module/VuFindSearch/src/VuFindSearch/Backend/EDS/ApiException.php
similarity index 94%
rename from module/VuFindSearch/src/VuFindSearch/Backend/EDS/Exception.php
rename to module/VuFindSearch/src/VuFindSearch/Backend/EDS/ApiException.php
index 71548aea59a..ef3d169aabf 100644
--- a/module/VuFindSearch/src/VuFindSearch/Backend/EDS/Exception.php
+++ b/module/VuFindSearch/src/VuFindSearch/Backend/EDS/ApiException.php
@@ -1,6 +1,6 @@
 <?php
 /**
- * EBSCO EdsApi Exception class
+ * EBSCO API Exception class
  *
  * PHP version 7
  *
@@ -25,17 +25,19 @@
  * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  * @link     https://vufind.org
  */
+namespace VuFindSearch\Backend\EDS;
 
 /**
- * EBSCO EdsApi Exception class
+ * EBSCO API Exception class
  *
  * @category EBSCOIndustries
  * @package  EBSCO
  * @author   Michelle Milton <mmilton@epnet.com>
+ * @author   Cornelius Amzar <cornelius.amzar@bsz-bw.de>
  * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  * @link     https://vufind.org
  */
-class EbscoEdsApiException extends \VuFindSearch\Backend\Exception\BackendException
+class ApiException extends \VuFindSearch\Backend\Exception\BackendException
 {
     /**
      * Error message details returned from the API
diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/EDS/Backend.php b/module/VuFindSearch/src/VuFindSearch/Backend/EDS/Backend.php
index 8ebba088cbc..6348fcb8a27 100644
--- a/module/VuFindSearch/src/VuFindSearch/Backend/EDS/Backend.php
+++ b/module/VuFindSearch/src/VuFindSearch/Backend/EDS/Backend.php
@@ -22,25 +22,20 @@
  * @category VuFind
  * @package  Search
  * @author   Michelle Milton <mmilton@epnet.com>
+ * @author   Cornelius Amzar <cornelius.amzar@bsz-bw.de>
  * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  * @link     https://vufind.org
  */
 namespace VuFindSearch\Backend\EDS;
 
 use Exception;
-
 use VuFindSearch\Backend\AbstractBackend;
-
 use VuFindSearch\Backend\EDS\Zend2 as ApiClient;
-
 use VuFindSearch\Backend\Exception\BackendException;
-
 use VuFindSearch\ParamBag;
 use VuFindSearch\Query\AbstractQuery;
-
 use VuFindSearch\Response\RecordCollectionFactoryInterface;
 use VuFindSearch\Response\RecordCollectionInterface;
-
 use Zend\Cache\Storage\Adapter\AbstractAdapter as CacheAdapter;
 use Zend\Config\Config;
 use Zend\Session\Container as SessionContainer;
@@ -232,7 +227,7 @@ class Backend extends AbstractBackend
         try {
             $response = $this->client
                 ->search($searchModel, $authenticationToken, $sessionToken);
-        } catch (\EbscoEdsApiException $e) {
+        } catch (ApiException $e) {
             // if the auth or session token was invalid, try once more
             switch ($e->getApiErrorCode()) {
             case 104:
@@ -294,7 +289,7 @@ class Backend extends AbstractBackend
             $response = $this->client->retrieve(
                 $an, $dbId, $authenticationToken, $sessionToken, $hlTerms
             );
-        } catch (\EbscoEdsApiException $e) {
+        } catch (ApiException $e) {
             // if the auth or session token was invalid, try once more
             switch ($e->getApiErrorCode()) {
             case 104:
@@ -535,7 +530,7 @@ class Backend extends AbstractBackend
         try {
             $authToken = $this->getAuthenticationToken();
             $results = $this->client->createSession($profile, $isGuest, $authToken);
-        } catch (\EbscoEdsApiException $e) {
+        } catch (ApiException $e) {
             $errorCode = $e->getApiErrorCode();
             $desc = $e->getApiErrorDescription();
             $this->debugPrint(
@@ -577,7 +572,7 @@ class Backend extends AbstractBackend
         }
         try {
             $response = $this->client->info($authenticationToken, $sessionToken);
-        } catch (\EbscoEdsApiException $e) {
+        } catch (ApiException $e) {
             if ($e->getApiErrorCode() == 104) {
                 try {
                     $authenticationToken = $this->getAuthenticationToken(true);
diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/EDS/Base.php b/module/VuFindSearch/src/VuFindSearch/Backend/EDS/Base.php
index 60f23797f8d..77065f7fcc6 100644
--- a/module/VuFindSearch/src/VuFindSearch/Backend/EDS/Base.php
+++ b/module/VuFindSearch/src/VuFindSearch/Backend/EDS/Base.php
@@ -22,13 +22,12 @@
  * @category EBSCOIndustries
  * @package  EBSCO
  * @author   Michelle Milton <mmilton@epnet.com>
+ * @author   Cornelius Amzar <cornelius.amzar@bsz-bw.de>
  * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  * @link     http://edswiki.ebscohost.com/EDS_API_Documentation
  */
 namespace VuFindSearch\Backend\EDS;
 
-require_once dirname(__FILE__) . '/Exception.php';
-
 /**
  * EBSCO Search API abstract base class
  *
@@ -38,7 +37,7 @@ require_once dirname(__FILE__) . '/Exception.php';
  * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  * @link     http://edswiki.ebscohost.com/EDS_API_Documentation
  */
-abstract class EdsApi_REST_Base
+abstract class Base
 {
     /**
      * A boolean value determining whether to print debug information
@@ -288,7 +287,7 @@ abstract class EdsApi_REST_Base
      * @param string $message       Message to POST if $method is POST
      * @param string $messageFormat Format of request $messageBody and responses
      *
-     * @throws \EbscoEdsApiException
+     * @throws ApiException
      * @return object         EDS API response (or an Error object).
      */
     protected function call($baseUrl, $headerParams, $params = [],
@@ -323,7 +322,7 @@ abstract class EdsApi_REST_Base
      *
      * @param array $input The raw response from Summon
      *
-     * @throws EbscoEdsApiException
+     * @throws ApiException
      * @return array       The processed response from EDS API
      */
     protected function process($input)
@@ -331,14 +330,14 @@ abstract class EdsApi_REST_Base
         //process response.
         try {
             $result = json_decode($input, true);
-        } catch (Exception $e) {
-            throw new EbscoEdsApiException(
+        } catch (\Exception $e) {
+            throw new ApiException(
                 'An error occurred when processing EDS Api response: '
                 . $e->getMessage()
             );
         }
         if (!isset($result)) {
-            throw new EbscoEdsApiException('Unknown error processing response');
+            throw new ApiException('Unknown error processing response');
         }
         return $result;
     }
diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/EDS/Zend2.php b/module/VuFindSearch/src/VuFindSearch/Backend/EDS/Zend2.php
index 9e6e9d087f4..9d115379964 100644
--- a/module/VuFindSearch/src/VuFindSearch/Backend/EDS/Zend2.php
+++ b/module/VuFindSearch/src/VuFindSearch/Backend/EDS/Zend2.php
@@ -22,12 +22,12 @@
  * @category EBSCOIndustries
  * @package  EBSCO
  * @author   Michelle Milton <mmilton@epnet.com>
+ * @author   Cornelius Amzar <cornelius.amzar@bsz-bw.de>
  * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  * @link     https://vufind.org
  */
 namespace VuFindSearch\Backend\EDS;
 
-require_once dirname(__FILE__) . '/Base.php';
 use Zend\Http\Client\Adapter\Curl as CurlAdapter;
 use Zend\Http\Client as Zend2HttpClient;
 use Zend\Log\LoggerAwareInterface;
@@ -41,7 +41,7 @@ use Zend\Log\LoggerAwareInterface;
  * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  * @link     https://vufind.org
  */
-class Zend2 extends EdsApi_REST_Base implements LoggerAwareInterface
+class Zend2 extends Base implements LoggerAwareInterface
 {
     use \VuFind\Log\LoggerAwareTrait;
 
@@ -119,7 +119,7 @@ class Zend2 extends EdsApi_REST_Base implements LoggerAwareInterface
      * @param string $messageBody   Message body to for HTTP Request
      * @param string $messageFormat Format of request $messageBody and respones
      *
-     * @throws EbscoEdsApiException
+     * @throws ApiException
      * @return string               HTTP response body
      */
     protected function httpRequest($baseUrl, $method, $queryString, $headers,
@@ -141,7 +141,7 @@ class Zend2 extends EdsApi_REST_Base implements LoggerAwareInterface
         $this->client->setEncType($messageFormat);
         $result = $this->client->send();
         if (!$result->isSuccess()) {
-            throw new \EbscoEdsApiException(json_decode($result->getBody(), true));
+            throw new ApiException(json_decode($result->getBody(), true));
         }
         return $result->getBody();
     }
-- 
GitLab