diff --git a/module/VuFind/src/VuFind/Controller/CoverController.php b/module/VuFind/src/VuFind/Controller/CoverController.php index ee1de5a5a5e8fa7097557f71f9ec42b549d7a16d..430ae5e6595cec0c68e8827169c21977a211c987 100644 --- a/module/VuFind/src/VuFind/Controller/CoverController.php +++ b/module/VuFind/src/VuFind/Controller/CoverController.php @@ -80,7 +80,7 @@ class CoverController extends AbstractBase $this->getConfig(), $this->serviceLocator->get('VuFind\Content\Covers\PluginManager'), $this->serviceLocator->get('VuFindTheme\ThemeInfo'), - $this->serviceLocator->get('VuFindHttp\HttpService')->createClient(), + $this->serviceLocator->get('VuFindHttp\HttpService'), $cacheDir ); $initializer = new \VuFind\ServiceManager\ServiceInitializer(); diff --git a/module/VuFind/src/VuFind/Cover/Loader.php b/module/VuFind/src/VuFind/Cover/Loader.php index d357a56acfba0cd6f4aa4e5c33047fb8e340168b..fe312fc97dd62bff11346cd67b47dd3a60847f08 100644 --- a/module/VuFind/src/VuFind/Cover/Loader.php +++ b/module/VuFind/src/VuFind/Cover/Loader.php @@ -72,11 +72,11 @@ class Loader extends \VuFind\ImageLoader protected $apiManager; /** - * HTTP client + * HTTP client factory * - * @var \Zend\Http\Client + * @var \VuFindHttp\HttpService */ - protected $client; + protected $httpService; /** * Directory to store downloaded images @@ -144,22 +144,23 @@ class Loader extends \VuFind\ImageLoader /** * Constructor * - * @param \Zend\Config\Config $config VuFind configuration - * @param ApiManager $manager Plugin manager for API handlers - * @param \VuFindTheme\ThemeInfo $theme VuFind theme tools - * @param \Zend\Http\Client $client HTTP client - * @param string $baseDir Directory to store downloaded images - * (set to system temp dir if not otherwise specified) + * @param \Zend\Config\Config $config VuFind configuration + * @param ApiManager $manager Plugin manager for API handlers + * @param \VuFindTheme\ThemeInfo $theme VuFind theme tools + * @param \VuFindHttp\HttpService $httpService HTTP client factory + * @param string $baseDir Directory to store downloaded + * images (set to system temp dir if not otherwise specified) */ public function __construct($config, ApiManager $manager, - \VuFindTheme\ThemeInfo $theme, \Zend\Http\Client $client, $baseDir = null + \VuFindTheme\ThemeInfo $theme, \VuFindHttp\HttpService $httpService, + $baseDir = null ) { $this->setThemeInfo($theme); $this->config = $config; $this->configuredFailImage = isset($config->Content->noCoverAvailableImage) ? $config->Content->noCoverAvailableImage : null; $this->apiManager = $manager; - $this->client = $client; + $this->httpService = $httpService; $this->baseDir = (null === $baseDir) ? rtrim(sys_get_temp_dir(), '\\/') . '/covers' : rtrim($baseDir, '\\/'); @@ -598,7 +599,7 @@ class Loader extends \VuFind\ImageLoader return true; } else { // Attempt to pull down the image: - $result = $this->client->setUri($url)->send(); + $result = $this->httpService->createClient($url)->send(); if (!$result->isSuccess()) { $this->debug('Failed to retrieve image from ' . $url); return false; diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Cover/LoaderTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Cover/LoaderTest.php index ae4d1285a37915bf64cfafcee0e2f31426bcfafc..00fc23a1430cdb7a69a652c6666bc9f5caa2a11a 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Cover/LoaderTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Cover/LoaderTest.php @@ -30,7 +30,6 @@ namespace VuFindTest\Cover; use VuFind\Cover\Loader; use VuFindTheme\ThemeInfo; use Zend\Config\Config; -use Zend\Http\Client\Adapter\Test as TestAdapter; /** * Cover Loader Test Class @@ -134,12 +133,12 @@ class LoaderTest extends \VuFindTest\Unit\TestCase * @param array $config Configuration * @param \VuFind\Content\Covers\PluginManager $manager Plugin manager (null to create mock) * @param ThemeInfo $theme Theme info object (null to create default) - * @param \Zend\Http\Client $client HTTP client (null to create TestAdapter) + * @param \VuFindHttp\HttpService $httpService HTTP client factory * @param array|bool $mock Array of functions to mock, or false for real object * * @return Loader */ - protected function getLoader($config = [], $manager = null, $theme = null, $client = null, $mock = false) + protected function getLoader($config = [], $manager = null, $theme = null, $httpService = null, $mock = false) { $config = new Config($config); if (null === $manager) { @@ -148,18 +147,16 @@ class LoaderTest extends \VuFindTest\Unit\TestCase if (null === $theme) { $theme = new ThemeInfo($this->getThemeDir(), $this->testTheme); } - if (null === $client) { - $adapter = new TestAdapter(); - $client = new \Zend\Http\Client(); - $client->setAdapter($adapter); + if (null === $httpService) { + $httpService = $this->getMockBuilder('VuFindHttp\HttpService')->getMock(); } if ($mock) { return $this->getMockBuilder(__NAMESPACE__ . '\MockLoader') ->setMethods($mock) - ->setConstructorArgs([$config, $manager, $theme, $client]) + ->setConstructorArgs([$config, $manager, $theme, $httpService]) ->getMock(); } - return new Loader($config, $manager, $theme, $client); + return new Loader($config, $manager, $theme, $httpService); } /**