diff --git a/module/VuFind/src/VuFind/Search/Base/Results.php b/module/VuFind/src/VuFind/Search/Base/Results.php index e86381fd7ab861daada4a3a15bd2b37f26d0ab54..1bd9c895a5684e8a7565cd16f4ce552d5a9315ea 100644 --- a/module/VuFind/src/VuFind/Search/Base/Results.php +++ b/module/VuFind/src/VuFind/Search/Base/Results.php @@ -26,10 +26,10 @@ * @link https://vufind.org Main Page */ namespace VuFind\Search\Base; -use VuFind\Search\Factory\UrlQueryHelperFactory, Zend\Paginator\Paginator, - Zend\ServiceManager\ServiceLocatorAwareInterface, - Zend\ServiceManager\ServiceLocatorInterface; +use VuFind\Record\Loader; +use VuFind\Search\Factory\UrlQueryHelperFactory; use VuFindSearch\Service as SearchService; +use Zend\Paginator\Paginator; /** * Abstract results search model. @@ -42,12 +42,8 @@ use VuFindSearch\Service as SearchService; * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link https://vufind.org Main Page */ -abstract class Results implements ServiceLocatorAwareInterface +abstract class Results { - use \Zend\ServiceManager\ServiceLocatorAwareTrait { - setServiceLocator as setServiceLocatorThroughTrait; - } - /** * Search parameters * @@ -140,15 +136,27 @@ abstract class Results implements ServiceLocatorAwareInterface */ protected $searchService; + /** + * Record loader + * + * @var Loader + */ + protected $recordLoader; + /** * Constructor * - * @param \VuFind\Search\Base\Params $params Object representing user search - * parameters. + * @param \VuFind\Search\Base\Params $params Object representing user + * search parameters. + * @param SearchService $searchService Search service + * @param Loader $recordLoader Record loader */ - public function __construct(Params $params) - { + public function __construct(Params $params, SearchService $searchService, + Loader $recordLoader + ) { $this->setParams($params); + $this->searchService = $searchService; + $this->recordLoader = $recordLoader; } /** @@ -540,22 +548,6 @@ abstract class Results implements ServiceLocatorAwareInterface $this->recommend = $recommend; } - /** - * Set the service locator. - * - * @param ServiceLocatorInterface $serviceLocator Locator to register - * - * @return Results - */ - public function setServiceLocator(ServiceLocatorInterface $serviceLocator) - { - // If this isn't the top-level manager, get its parent: - if ($serviceLocator instanceof ServiceLocatorAwareInterface) { - $serviceLocator = $serviceLocator->getServiceLocator(); - } - return $this->setServiceLocatorThroughTrait($serviceLocator); - } - /** * Return search service. * @@ -566,9 +558,6 @@ abstract class Results implements ServiceLocatorAwareInterface */ protected function getSearchService() { - if (!$this->searchService) { - $this->searchService = $this->getServiceLocator()->get('VuFind\Search'); - } return $this->searchService; } diff --git a/module/VuFind/src/VuFind/Search/Favorites/Results.php b/module/VuFind/src/VuFind/Search/Favorites/Results.php index 8ea2c0b557616a55a1ff67333cce071ad5c0d2a0..66fdb6f884ca8a9fd798d226137fc6c66da703a8 100644 --- a/module/VuFind/src/VuFind/Search/Favorites/Results.php +++ b/module/VuFind/src/VuFind/Search/Favorites/Results.php @@ -31,6 +31,8 @@ use VuFind\Db\Table\UserList as ListTable; use VuFind\Exception\ListPermission as ListPermissionException; use VuFind\Search\Base\Results as BaseResults; use VuFind\Record\Cache; +use VuFind\Record\Loader; +use VuFindSearch\Service as SearchService; use ZfcRbac\Service\AuthorizationServiceAwareInterface; use ZfcRbac\Service\AuthorizationServiceAwareTrait; @@ -81,13 +83,16 @@ class Results extends BaseResults * * @param \VuFind\Search\Base\Params $params Object representing user * search parameters. + * @param SearchService $searchService Search service + * @param Loader $recordLoader Record loader * @param ResourceTable $resourceTable Resource table * @param ListTable $listTable UserList table */ public function __construct(\VuFind\Search\Base\Params $params, + SearchService $searchService, Loader $recordLoader, ResourceTable $resourceTable, ListTable $listTable ) { - parent::__construct($params); + parent::__construct($params, $searchService, $recordLoader); $this->resourceTable = $resourceTable; $this->listTable = $listTable; } @@ -205,9 +210,8 @@ class Results extends BaseResults ]; } - $recordLoader = $this->getServiceLocator()->get('VuFind\RecordLoader'); - $recordLoader->setCacheContext(Cache::CONTEXT_FAVORITE); - $this->results = $recordLoader->loadBatch($recordsToRequest); + $this->recordLoader->setCacheContext(Cache::CONTEXT_FAVORITE); + $this->results = $this->recordLoader->loadBatch($recordsToRequest); } /** diff --git a/module/VuFind/src/VuFind/Search/MixedList/Results.php b/module/VuFind/src/VuFind/Search/MixedList/Results.php index 582ed29f810464408b49bd953d2ab7a2fd1e37e7..f77dddbcb95baf405833cb4c194822398a9500f0 100644 --- a/module/VuFind/src/VuFind/Search/MixedList/Results.php +++ b/module/VuFind/src/VuFind/Search/MixedList/Results.php @@ -62,8 +62,7 @@ class Results extends BaseResults protected function performSearch() { $recordsToRequest = $this->getParams()->getRecordsToRequest(); - $this->results = $this->getServiceLocator()->get('VuFind\RecordLoader') - ->loadBatch($recordsToRequest); + $this->results = $this->recordLoader->loadBatch($recordsToRequest); $this->resultTotal = count($this->results); } } diff --git a/module/VuFind/src/VuFind/Search/Results/PluginFactory.php b/module/VuFind/src/VuFind/Search/Results/PluginFactory.php index a5eab343f719e8f524259928eae0b51cf724297b..a1dfdb18bb28b9366d6a179ed49ebcf02e895735 100644 --- a/module/VuFind/src/VuFind/Search/Results/PluginFactory.php +++ b/module/VuFind/src/VuFind/Search/Results/PluginFactory.php @@ -64,8 +64,11 @@ class PluginFactory extends \VuFind\ServiceManager\AbstractPluginFactory ) { $params = $serviceLocator->getServiceLocator() ->get('VuFind\SearchParamsPluginManager')->get($requestedName); + $searchService = $serviceLocator->getServiceLocator() + ->get('VuFind\Search'); + $recordLoader = $serviceLocator->getServiceLocator() + ->get('VuFind\RecordLoader'); $class = $this->getClassName($name, $requestedName); - array_unshift($extraParams, $params); - return new $class(...$extraParams); + return new $class($params, $searchService, $recordLoader, ...$extraParams); } } diff --git a/module/VuFind/src/VuFind/Search/SolrAuth/Results.php b/module/VuFind/src/VuFind/Search/SolrAuth/Results.php index 9b81dd415428eadc1d1e85e3eca6d39455735677..aa8ffc769b6d6651147c42bd6bf5b5f15a544044 100644 --- a/module/VuFind/src/VuFind/Search/SolrAuth/Results.php +++ b/module/VuFind/src/VuFind/Search/SolrAuth/Results.php @@ -26,6 +26,8 @@ * @link https://vufind.org Main Page */ namespace VuFind\Search\SolrAuth; +use VuFind\Record\Loader; +use VuFindSearch\Service as SearchService; /** * Solr Authority Search Parameters @@ -41,12 +43,15 @@ class Results extends \VuFind\Search\Solr\Results /** * Constructor * - * @param \VuFind\Search\Base\Params $params Object representing user search - * parameters. + * @param \VuFind\Search\Base\Params $params Object representing user + * search parameters. + * @param SearchService $searchService Search service + * @param Loader $recordLoader Record loader */ - public function __construct(\VuFind\Search\Base\Params $params) - { - parent::__construct($params); + public function __construct(\VuFind\Search\Base\Params $params, + SearchService $searchService, Loader $recordLoader + ) { + parent::__construct($params, $searchService, $recordLoader); $this->backendId = 'SolrAuth'; } } diff --git a/module/VuFind/src/VuFind/Search/SolrAuthor/Results.php b/module/VuFind/src/VuFind/Search/SolrAuthor/Results.php index d12e633069c00207a4eef1bd518c6d15314b9567..4d896f9a8fc3089e216472ebeab56a3377e0d666 100644 --- a/module/VuFind/src/VuFind/Search/SolrAuthor/Results.php +++ b/module/VuFind/src/VuFind/Search/SolrAuthor/Results.php @@ -27,6 +27,8 @@ */ namespace VuFind\Search\SolrAuthor; use VuFind\Search\Solr\Results as SolrResults; +use VuFind\Record\Loader; +use VuFindSearch\Service as SearchService; /** * Author Search Options @@ -42,13 +44,15 @@ class Results extends SolrResults /** * Constructor * - * @param \VuFind\Search\Base\Params $params Object representing user search - * parameters. + * @param \VuFind\Search\Base\Params $params Object representing user + * search parameters. + * @param SearchService $searchService Search service + * @param Loader $recordLoader Record loader */ - public function __construct($params) - { - // Call parent constructor: - parent::__construct($params); + public function __construct(\VuFind\Search\Base\Params $params, + SearchService $searchService, Loader $recordLoader + ) { + parent::__construct($params, $searchService, $recordLoader); } /** diff --git a/module/VuFind/src/VuFind/Search/SolrReserves/Results.php b/module/VuFind/src/VuFind/Search/SolrReserves/Results.php index c611199ccafba7b283456d0a212896d3067f42b0..eb1ce36626a0515e26e799a9bc621dfc149f4738 100644 --- a/module/VuFind/src/VuFind/Search/SolrReserves/Results.php +++ b/module/VuFind/src/VuFind/Search/SolrReserves/Results.php @@ -27,6 +27,8 @@ * @link https://vufind.org Main Page */ namespace VuFind\Search\SolrReserves; +use VuFind\Record\Loader; +use VuFindSearch\Service as SearchService; /** * Solr Reserves Search Parameters @@ -43,12 +45,15 @@ class Results extends \VuFind\Search\Solr\Results /** * Constructor * - * @param \VuFind\Search\Base\Params $params Object representing user search - * parameters. + * @param \VuFind\Search\Base\Params $params Object representing user + * search parameters. + * @param SearchService $searchService Search service + * @param Loader $recordLoader Record loader */ - public function __construct(\VuFind\Search\Base\Params $params) - { - parent::__construct($params); + public function __construct(\VuFind\Search\Base\Params $params, + SearchService $searchService, Loader $recordLoader + ) { + parent::__construct($params, $searchService, $recordLoader); $this->backendId = 'SolrReserves'; } } diff --git a/module/VuFind/src/VuFind/Search/SolrWeb/Results.php b/module/VuFind/src/VuFind/Search/SolrWeb/Results.php index 7c1c30d1da2018146f8856ae8c6ff270b399f96b..c3644b63f69115f38fe3daf8769171fc40211ffb 100644 --- a/module/VuFind/src/VuFind/Search/SolrWeb/Results.php +++ b/module/VuFind/src/VuFind/Search/SolrWeb/Results.php @@ -26,6 +26,8 @@ * @link https://vufind.org Main Page */ namespace VuFind\Search\SolrWeb; +use VuFind\Record\Loader; +use VuFindSearch\Service as SearchService; /** * Solr Web Search Parameters @@ -41,12 +43,15 @@ class Results extends \VuFind\Search\Solr\Results /** * Constructor * - * @param \VuFind\Search\Base\Params $params Object representing user search - * parameters. + * @param \VuFind\Search\Base\Params $params Object representing user + * search parameters. + * @param SearchService $searchService Search service + * @param Loader $recordLoader Record loader */ - public function __construct(\VuFind\Search\Base\Params $params) - { - parent::__construct($params); + public function __construct(\VuFind\Search\Base\Params $params, + SearchService $searchService, Loader $recordLoader + ) { + parent::__construct($params, $searchService, $recordLoader); $this->backendId = 'SolrWeb'; } } diff --git a/module/VuFind/src/VuFind/Search/Tags/Results.php b/module/VuFind/src/VuFind/Search/Tags/Results.php index cda2bc4dcd0c98e00d69229db5f01068a29eb063..d511e718a18021e25977a8da1e7116e3a79538c5 100644 --- a/module/VuFind/src/VuFind/Search/Tags/Results.php +++ b/module/VuFind/src/VuFind/Search/Tags/Results.php @@ -27,7 +27,9 @@ */ namespace VuFind\Search\Tags; use VuFind\Db\Table\Tags as TagsTable; +use VuFind\Record\Loader; use VuFind\Search\Base\Results as BaseResults; +use VuFindSearch\Service as SearchService; /** * Search Tags Results @@ -50,14 +52,16 @@ class Results extends BaseResults /** * Constructor * - * @param \VuFind\Search\Base\Params $params Object representing user search - * parameters. - * @param TagsTable $tagsTable Resource table + * @param \VuFind\Search\Base\Params $params Object representing user + * search parameters. + * @param SearchService $searchService Search service + * @param Loader $recordLoader Record loader + * @param TagsTable $tagsTable Resource table */ public function __construct(\VuFind\Search\Base\Params $params, - TagsTable $tagsTable + SearchService $searchService, Loader $recordLoader, TagsTable $tagsTable ) { - parent::__construct($params); + parent::__construct($params, $searchService, $recordLoader); $this->tagsTable = $tagsTable; } @@ -124,7 +128,7 @@ class Results extends BaseResults $callback = function ($row) { return ['id' => $row['record_id'], 'source' => $row['source']]; }; - $this->results = $this->getServiceLocator()->get('VuFind\RecordLoader') + $this->results = $this->recordLoader ->loadBatch(array_map($callback, $results)); } diff --git a/module/VuFind/src/VuFindTest/Search/TestHarness/Results.php b/module/VuFind/src/VuFindTest/Search/TestHarness/Results.php index 5618e68a0bf221bb2ed1e811177401fb2ee29cd3..a915805b9818fec824dd22f73ba0e722f2abba4e 100644 --- a/module/VuFind/src/VuFindTest/Search/TestHarness/Results.php +++ b/module/VuFind/src/VuFindTest/Search/TestHarness/Results.php @@ -26,6 +26,8 @@ * @link https://vufind.org Main Page */ namespace VuFindTest\Search\TestHarness; +use VuFind\Record\Loader; +use VuFindSearch\Service as SearchService; use VuFindTest\RecordDriver\TestHarness as RecordDriver; /** @@ -65,14 +67,19 @@ class Results extends \VuFind\Search\Base\Results /** * Constructor * - * @param \VuFind\Search\Base\Params $params Object representing user search - * parameters. - * @param int $total Total result set size to simulate - * @param array $facets Facet response (optional) + * @param \VuFind\Search\Base\Params $params Object representing user + * search parameters. + * @param SearchService $searchService Search service + * @param Loader $recordLoader Record loader + * @param int $total Total result set size to + * simulate + * @param array $facets Facet response (optional) */ - public function __construct(Params $params, $total = 100, $facets = []) - { - parent::__construct($params); + public function __construct(\VuFind\Search\Base\Params $params, + SearchService $searchService, Loader $recordLoader, + $total = 100, $facets = [] + ) { + parent::__construct($params, $searchService, $recordLoader); $this->fakeExpectedTotal = $total; $this->searchId = 'fake'; // fill a fake value here so we don't hit the DB $this->facets = $facets; diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/ResultScrollerTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/ResultScrollerTest.php index 40258c91ff4c0c52af29f96e0e2d0b2ad79a4ec2..b473f7da415f770281932ecb0668c80fe29a4269 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/ResultScrollerTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/ResultScrollerTest.php @@ -312,7 +312,13 @@ class ResultScrollerTest extends TestCase $params = new \VuFindTest\Search\TestHarness\Params($options, $pm); $params->setPage($page); $params->setLimit($limit); - $results = new \VuFindTest\Search\TestHarness\Results($params, $total); + $ss = $this->getMockBuilder('VuFindSearch\Service') + ->disableOriginalConstructor()->getMock(); + $rl = $this->getMockBuilder('VuFind\Record\Loader') + ->disableOriginalConstructor()->getMock(); + $results = new \VuFindTest\Search\TestHarness\Results( + $params, $ss, $rl, $total + ); return $results; } diff --git a/module/VuFindApi/tests/unit-tests/src/VuFindTest/Formatter/FacetFormatterTest.php b/module/VuFindApi/tests/unit-tests/src/VuFindTest/Formatter/FacetFormatterTest.php index 4c15ee7ceb7e76e1f54817c1b02357e095de5182..7fe9d41fc6274757d8d0fb4a7dd5abe8b23bc620 100644 --- a/module/VuFindApi/tests/unit-tests/src/VuFindTest/Formatter/FacetFormatterTest.php +++ b/module/VuFindApi/tests/unit-tests/src/VuFindTest/Formatter/FacetFormatterTest.php @@ -184,7 +184,11 @@ class FacetFormatterTest extends \VuFindTest\Unit\TestCase $configManager = $this->getMock('VuFind\Config\PluginManager'); $params = new Params(new Options($configManager), $configManager); $params->initFromRequest(new \Zend\Stdlib\Parameters($request)); - return new Results($params, 100, $facetData); + $ss = $this->getMockBuilder('VuFindSearch\Service') + ->disableOriginalConstructor()->getMock(); + $rl = $this->getMockBuilder('VuFind\Record\Loader') + ->disableOriginalConstructor()->getMock(); + return new Results($params, $ss, $rl, 100, $facetData); } /**