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 71548aea59a29950cdfa329e040f30be82ea9b7b..ef3d169aabf5c59df89f494687c1b725cc3d9c11 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 8ebba088cbcdca903c21937235874997200ba2b5..6348fcb8a273cb11f24479049dce58b22a5155e1 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 60f23797f8d3c77dda0a0da63abb2708e39fa499..77065f7fcc6673655da6adacb5aa0198dd0738b0 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 9e6e9d087f4612a2a34c7bbd5237737841618378..9d115379964b62b139c7dd887c1f92926892ff02 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(); }