diff --git a/module/VuFind/src/VuFind/Theme/Root/Helper/AbstractSyndetics.php b/module/VuFind/src/VuFind/Theme/Root/Helper/AbstractSyndetics.php index 204b71843afbe0ebef1767bf6d47a9c7eaeda3e9..a9dbcfa1d98fc908e75b3153075bfd16fb58a381 100644 --- a/module/VuFind/src/VuFind/Theme/Root/Helper/AbstractSyndetics.php +++ b/module/VuFind/src/VuFind/Theme/Root/Helper/AbstractSyndetics.php @@ -38,6 +38,7 @@ use Zend\View\Helper\AbstractHelper; * @link http://vufind.org/wiki/building_a_recommendations_module Wiki */ abstract class AbstractSyndetics extends AbstractHelper + implements \VuFindHttp\HttpServiceAwareInterface { /** * VuFind configuration @@ -53,6 +54,13 @@ abstract class AbstractSyndetics extends AbstractHelper */ protected $isbn; + /** + * HTTP service + * + * @var \VuFindHttp\HttpServiceInterface + */ + protected $httpService = null; + /** * Constructor */ @@ -97,11 +105,28 @@ abstract class AbstractSyndetics extends AbstractHelper /** * Get an HTTP client * + * @param string $url URL for client to use + * * @return \Zend\Http\Client */ - protected function getHttpClient() + protected function getHttpClient($url) + { + if (null === $this->httpService) { + throw new \Exception('HTTP service missing.'); + } + return $this->httpService->createClient($url); + } + + /** + * Set the HTTP service to be used for HTTP requests. + * + * @param HttpServiceInterface $service HTTP service + * + * @return void + */ + public function setHttpService(\VuFindHttp\HttpServiceInterface $service) { - return new \VuFind\Http\Client(); + $this->httpService = $service; } /** diff --git a/module/VuFind/src/VuFind/Theme/Root/Helper/AuthorNotes.php b/module/VuFind/src/VuFind/Theme/Root/Helper/AuthorNotes.php index e9f6ae775a85f526844b9b95e45fc9be35ef1c1f..1758ce3f6a7b1b00387f40316fb5cb2c993ae964 100644 --- a/module/VuFind/src/VuFind/Theme/Root/Helper/AuthorNotes.php +++ b/module/VuFind/src/VuFind/Theme/Root/Helper/AuthorNotes.php @@ -117,9 +117,7 @@ class AuthorNotes extends AbstractSyndetics $anotes = array(); //find out if there are any notes - $client = $this->getHttpClient(); - $client->setUri($url); - $result = $client->setMethod('GET')->send(); + $result = $this->getHttpClient($url)->send(); if (!$result->isSuccess()) { return $anotes; } @@ -137,8 +135,7 @@ class AuthorNotes extends AbstractSyndetics $url = $baseUrl . '/index.aspx?isbn=' . $this->getIsbn10() . '/' . $sourceInfo['file'] . '&client=' . $id . '&type=rw12,hw7'; - $client->setUri($url); - $result2 = $client->send(); + $result2 = $this->getHttpClient($url)->send(); if (!$result2->isSuccess()) { continue; } diff --git a/module/VuFind/src/VuFind/Theme/Root/Helper/Excerpt.php b/module/VuFind/src/VuFind/Theme/Root/Helper/Excerpt.php index fae71bba5bf3a63e9ed2519be1055aed68b4db97..f0ff97963e0465fb84c2bed37e6043f784e42853 100644 --- a/module/VuFind/src/VuFind/Theme/Root/Helper/Excerpt.php +++ b/module/VuFind/src/VuFind/Theme/Root/Helper/Excerpt.php @@ -118,9 +118,7 @@ class Excerpt extends AbstractSyndetics $review = array(); //find out if there are any excerpts - $client = $this->getHttpClient(); - $client->setUri($url); - $result = $client->setMethod('GET')->send(); + $result = $this->getHttpClient($url)->send(); if (!$result->isSuccess()) { return $review; } @@ -138,8 +136,7 @@ class Excerpt extends AbstractSyndetics $url = $baseUrl . '/index.aspx?isbn=' . $this->getIsbn10() . '/' . $sourceInfo['file'] . '&client=' . $id . '&type=rw12,hw7'; - $client->setUri($url); - $result2 = $client->send(); + $result2 = $this->getHttpClient($url)->send(); if (!$result2->isSuccess()) { continue; } diff --git a/module/VuFind/src/VuFind/Theme/Root/Helper/Reviews.php b/module/VuFind/src/VuFind/Theme/Root/Helper/Reviews.php index 89f762af30adc341496d973e55194fc191b9780d..ac2aa160b54ad4f1e663eab94a67e0353b8f000a 100644 --- a/module/VuFind/src/VuFind/Theme/Root/Helper/Reviews.php +++ b/module/VuFind/src/VuFind/Theme/Root/Helper/Reviews.php @@ -129,9 +129,7 @@ class Reviews extends AbstractSyndetics $url = 'http://' . $endpoint . $requestURI . '?' . $encodedParams . '&Signature=' . rawurlencode(base64_encode($hmacHash)); - $client = $this->getHttpClient(); - $client->setUri($url); - $result = $client->setMethod('GET')->send(); + $result = $this->getHttpClient($url)->send(); $data = !$result->isSuccess() ? false : simplexml_load_string($result->getBody()); @@ -292,9 +290,7 @@ class Reviews extends AbstractSyndetics $review = array(); //find out if there are any reviews - $client = $this->getHttpClient(); - $client->setUri($url); - $result = $client->setMethod('GET')->send(); + $result = $this->getHttpClient($url)->send(); if (!$result->isSuccess()) { return $review; } @@ -311,8 +307,7 @@ class Reviews extends AbstractSyndetics // Load reviews $url = $baseUrl . '/index.aspx?isbn=' . $this->getIsbn10() . '/' . $sourceInfo['file'] . '&client=' . $id . '&type=rw12,hw7'; - $client->setUri($url); - $result2 = $client->send(); + $result2 = $this->getHttpClient($url)->send(); if (!$result2->isSuccess()) { continue; } @@ -399,9 +394,7 @@ class Reviews extends AbstractSyndetics } //find out if there are any reviews - $client = $this->getHttpClient(); - $client->setUri($url); - $result = $client->setMethod('GET')->send(); + $result = $this->getHttpClient($url)->send(); // Was the request successful? if ($result->isSuccess()) { diff --git a/module/VuFind/src/VuFind/Theme/Root/Helper/VideoClips.php b/module/VuFind/src/VuFind/Theme/Root/Helper/VideoClips.php index 2900f928830ca4ea0d1d62d58cc547e55713419b..522e6e3ceab64f48545fdf4eba2f90fa83950b8b 100644 --- a/module/VuFind/src/VuFind/Theme/Root/Helper/VideoClips.php +++ b/module/VuFind/src/VuFind/Theme/Root/Helper/VideoClips.php @@ -117,9 +117,7 @@ class VideoClips extends AbstractSyndetics $vclips = array(); //find out if there are any clips - $client = $this->getHttpClient(); - $client->setUri($url); - $result = $client->setMethod('GET')->send(); + $result = $this->getHttpClient($url)->send(); if (!$result->isSuccess()) { return $vclips; } @@ -137,8 +135,7 @@ class VideoClips extends AbstractSyndetics $url = $baseUrl . '/index.aspx?isbn=' . $this->getIsbn10() . '/' . $sourceInfo['file'] . '&client=' . $id . '&type=rw12,hw7'; - $client->setUri($url); - $result2 = $client->send(); + $result2 = $this->getHttpClient($url)->send(); if (!$result2->isSuccess()) { continue; }