From 9bb4b79acbd67c8b235a7f443c0b95488ee3b886 Mon Sep 17 00:00:00 2001 From: Demian Katz Date: Tue, 30 Jul 2024 09:59:41 -0400 Subject: [PATCH 1/3] Trivial: add missing authority limit config examples. --- config/vufind/authority.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/vufind/authority.ini b/config/vufind/authority.ini index 17e2ff974db..4e603c1d714 100644 --- a/config/vufind/authority.ini +++ b/config/vufind/authority.ini @@ -3,6 +3,8 @@ [General] default_handler = AllFields ; Search handler to use if none is specified default_sort = relevance +default_limit = 20 +;limit_options = 10,20,40,60,80,100 case_sensitive_bools = true default_side_recommend[] = SideFacets:Facets:CheckboxFacets:authority ;default_record_fields = "*,score" From dfb3a95f421ece4c3121d67def9625c2da66c4f3 Mon Sep 17 00:00:00 2001 From: Demian Katz Date: Tue, 30 Jul 2024 13:53:27 -0400 Subject: [PATCH 2/3] Introduce GetServiceTrait. (#3843) --- module/VuFind/src/VuFind/CSV/Importer.php | 12 +-- .../src/VuFind/Controller/AbstractBase.php | 50 +++++------ .../src/VuFind/Controller/AbstractRecord.php | 30 ++++--- .../src/VuFind/Controller/AbstractSearch.php | 35 ++++---- .../VuFind/Controller/AbstractSolrSearch.php | 6 +- .../src/VuFind/Controller/AlmaController.php | 4 +- .../VuFind/Controller/AuthorController.php | 3 +- .../VuFind/Controller/BlenderController.php | 3 +- .../VuFind/Controller/BrowseController.php | 5 +- .../src/VuFind/Controller/CartController.php | 6 +- .../Controller/CollectionController.php | 3 +- .../Controller/CollectionsController.php | 5 +- .../VuFind/Controller/CombinedController.php | 15 ++-- .../VuFind/Controller/ContentController.php | 2 +- .../src/VuFind/Controller/EITController.php | 3 +- .../VuFind/Controller/EITrecordController.php | 3 +- .../src/VuFind/Controller/EdsController.php | 3 +- .../VuFind/Controller/EdsrecordController.php | 3 +- .../Controller/ExternalAuthController.php | 5 +- .../Controller/Feature/AlphaBrowseTrait.php | 2 +- .../Controller/Feature/ConfigPathTrait.php | 4 +- .../Feature/RecordVersionsSearchTrait.php | 2 +- .../VuFind/Controller/FeedbackController.php | 2 +- .../VuFind/Controller/HierarchyController.php | 3 +- .../src/VuFind/Controller/HoldsController.php | 2 +- .../src/VuFind/Controller/HoldsTrait.php | 2 +- .../VuFind/Controller/ILLRequestsTrait.php | 3 +- .../VuFind/Controller/InstallController.php | 18 ++-- .../Controller/LibGuidesAZController.php | 3 +- .../VuFind/Controller/LibGuidesController.php | 3 +- .../Controller/LibraryCardsController.php | 6 +- .../Controller/MyResearchController.php | 84 ++++++++----------- .../src/VuFind/Controller/OaiController.php | 4 +- .../VuFind/Controller/OverdriveController.php | 11 ++- .../src/VuFind/Controller/PrimoController.php | 3 +- .../Controller/PrimorecordController.php | 3 +- .../VuFind/Controller/RecordController.php | 3 +- .../VuFind/Controller/Search2Controller.php | 3 +- .../Controller/Search2recordController.php | 3 +- .../VuFind/Controller/SearchController.php | 21 ++--- ...ShibbolethLogoutNotificationController.php | 2 +- .../VuFind/Controller/ShortlinkController.php | 2 +- .../StorageRetrievalRequestsTrait.php | 3 +- .../VuFind/Controller/SummonController.php | 7 +- .../Controller/SummonrecordController.php | 3 +- .../VuFind/Controller/UpgradeController.php | 18 ++-- .../VuFind/Controller/WorldcatController.php | 3 +- .../Controller/WorldcatrecordController.php | 3 +- .../RateLimiter/RateLimiterManagerFactory.php | 13 +-- .../Search/Factory/AbstractBackendFactory.php | 14 +--- .../Factory/AbstractSolrBackendFactory.php | 13 ++- .../Search/Factory/BrowZineBackendFactory.php | 8 +- .../Search/Factory/EITBackendFactory.php | 9 +- .../Search/Factory/EdsBackendFactory.php | 19 ++--- .../Factory/LibGuidesBackendFactory.php | 8 +- .../Search/Factory/Pazpar2BackendFactory.php | 9 +- .../Search/Factory/PrimoBackendFactory.php | 14 ++-- .../Search/Factory/Search2BackendFactory.php | 3 +- .../Search/Factory/SolrAuthBackendFactory.php | 3 +- .../Factory/SolrDefaultBackendFactory.php | 3 +- .../Factory/SolrReservesBackendFactory.php | 3 +- .../Search/Factory/SolrWebBackendFactory.php | 3 +- .../Search/Factory/SummonBackendFactory.php | 11 +-- .../Search/Factory/WorldCatBackendFactory.php | 12 +-- .../Search/Solr/DeduplicationListener.php | 14 ++-- .../Search/Solr/HierarchicalFacetListener.php | 15 ++-- .../src/VuFind/Service/GetServiceTrait.php | 65 ++++++++++++++ module/VuFind/src/VuFind/XSLT/Importer.php | 12 +-- .../VuFindAdmin/Controller/AbstractAdmin.php | 3 +- .../Controller/AdminController.php | 2 +- .../Controller/ConfigController.php | 7 +- .../Controller/MaintenanceController.php | 6 +- .../Controller/OverdriveController.php | 3 +- .../Controller/SocialstatsController.php | 2 +- .../VuFindAdmin/Controller/TagsController.php | 8 +- .../src/VuFindApi/Controller/ApiTrait.php | 3 +- .../Controller/SearchApiController.php | 7 +- .../Controller/DevtoolsController.php | 9 +- 78 files changed, 327 insertions(+), 396 deletions(-) create mode 100644 module/VuFind/src/VuFind/Service/GetServiceTrait.php diff --git a/module/VuFind/src/VuFind/CSV/Importer.php b/module/VuFind/src/VuFind/CSV/Importer.php index ab7a3771296..71a16675a66 100644 --- a/module/VuFind/src/VuFind/CSV/Importer.php +++ b/module/VuFind/src/VuFind/CSV/Importer.php @@ -30,6 +30,7 @@ namespace VuFind\CSV; use Laminas\ServiceManager\ServiceLocatorInterface; +use VuFind\Service\GetServiceTrait; use VuFindSearch\Backend\Solr\Document\RawJSONDocument; use function count; @@ -45,12 +46,7 @@ */ class Importer { - /** - * Service locator - * - * @var ServiceLocatorInterface - */ - protected $serviceLocator; + use GetServiceTrait; /** * Base path for loading .ini files @@ -162,7 +158,7 @@ protected function writeData(array $data, string $index, bool $testMode): string if ($testMode) { return $json; } - $solr = $this->serviceLocator->get(\VuFind\Solr\Writer::class); + $solr = $this->getService(\VuFind\Solr\Writer::class); $solr->save($index, new RawJSONDocument($json), 'update'); return ''; // no output when not in test mode! } @@ -209,7 +205,7 @@ protected function processHeader(ImporterConfig $config, $in, string $mode): voi protected function getConfiguration(string $iniFile, $in): ImporterConfig { // Load properties file: - $resolver = $this->serviceLocator->get(\VuFind\Config\PathResolver::class); + $resolver = $this->getService(\VuFind\Config\PathResolver::class); $ini = $resolver->getConfigPath($iniFile, $this->configBaseDir); if (!file_exists($ini)) { throw new \Exception("Cannot load .ini file: {$ini}."); diff --git a/module/VuFind/src/VuFind/Controller/AbstractBase.php b/module/VuFind/src/VuFind/Controller/AbstractBase.php index 93cd8dfc91f..9d6958961d9 100644 --- a/module/VuFind/src/VuFind/Controller/AbstractBase.php +++ b/module/VuFind/src/VuFind/Controller/AbstractBase.php @@ -43,6 +43,7 @@ use VuFind\Http\PhpEnvironment\Request as HttpRequest; use VuFind\I18n\Translator\TranslatorAwareInterface; use VuFind\I18n\Translator\TranslatorAwareTrait; +use VuFind\Service\GetServiceTrait; use function intval; use function is_object; @@ -76,6 +77,7 @@ */ class AbstractBase extends AbstractActionController implements AccessPermissionInterface, TranslatorAwareInterface { + use GetServiceTrait; use TranslatorAwareTrait; /** @@ -97,13 +99,6 @@ class AbstractBase extends AbstractActionController implements AccessPermissionI */ protected $accessDeniedBehavior = null; - /** - * Service manager - * - * @var ServiceLocatorInterface - */ - protected $serviceLocator; - /** * Constructor * @@ -288,7 +283,7 @@ protected function createEmailViewModel($params = null, $defaultSubject = null) */ protected function getAuthManager() { - return $this->serviceLocator->get(\VuFind\Auth\Manager::class); + return $this->getService(\VuFind\Auth\Manager::class); } /** @@ -300,8 +295,7 @@ protected function getAuthManager() */ protected function getAuthorizationService() { - return $this->serviceLocator - ->get(\LmcRbacMvc\Service\AuthorizationService::class); + return $this->getService(\LmcRbacMvc\Service\AuthorizationService::class); } /** @@ -311,7 +305,7 @@ protected function getAuthorizationService() */ protected function getILSAuthenticator() { - return $this->serviceLocator->get(\VuFind\Auth\ILSAuthenticator::class); + return $this->getService(\VuFind\Auth\ILSAuthenticator::class); } /** @@ -331,7 +325,7 @@ protected function getUser(): ?UserEntityInterface */ protected function getViewRenderer() { - return $this->serviceLocator->get('ViewRenderer'); + return $this->getService('ViewRenderer'); } /** @@ -459,8 +453,7 @@ protected function catalogLogin() */ public function getConfig($id = 'config') { - return $this->serviceLocator->get(\VuFind\Config\PluginManager::class) - ->get($id); + return $this->getService(\VuFind\Config\PluginManager::class)->get($id); } /** @@ -470,7 +463,7 @@ public function getConfig($id = 'config') */ public function getILS() { - return $this->serviceLocator->get(\VuFind\ILS\Connection::class); + return $this->getService(\VuFind\ILS\Connection::class); } /** @@ -480,7 +473,7 @@ public function getILS() */ public function getRecordLoader() { - return $this->serviceLocator->get(\VuFind\Record\Loader::class); + return $this->getService(\VuFind\Record\Loader::class); } /** @@ -490,7 +483,7 @@ public function getRecordLoader() */ public function getRecordCache() { - return $this->serviceLocator->get(\VuFind\Record\Cache::class); + return $this->getService(\VuFind\Record\Cache::class); } /** @@ -500,7 +493,7 @@ public function getRecordCache() */ public function getRecordRouter() { - return $this->serviceLocator->get(\VuFind\Record\Router::class); + return $this->getService(\VuFind\Record\Router::class); } /** @@ -512,8 +505,7 @@ public function getRecordRouter() */ public function getTable($table) { - return $this->serviceLocator->get(\VuFind\Db\Table\PluginManager::class) - ->get($table); + return $this->getService(\VuFind\Db\Table\PluginManager::class)->get($table); } /** @@ -527,8 +519,7 @@ public function getTable($table) */ public function getDbService(string $name): \VuFind\Db\Service\DbServiceInterface { - return $this->serviceLocator->get(\VuFind\Db\Service\PluginManager::class) - ->get($name); + return $this->getService(\VuFind\Db\Service\PluginManager::class)->get($name); } /** @@ -638,7 +629,7 @@ public function confirm( */ protected function disableSessionWrites() { - $this->serviceLocator->get(\VuFind\Session\Settings::class)->disableWrite(); + $this->getService(\VuFind\Session\Settings::class)->disableWrite(); } /** @@ -648,7 +639,7 @@ protected function disableSessionWrites() */ public function getSearchMemory() { - return $this->serviceLocator->get(\VuFind\Search\Memory::class); + return $this->getService(\VuFind\Search\Memory::class); } /** @@ -658,8 +649,7 @@ public function getSearchMemory() */ protected function commentsEnabled() { - $check = $this->serviceLocator - ->get(\VuFind\Config\AccountCapabilities::class); + $check = $this->getService(\VuFind\Config\AccountCapabilities::class); return $check->getCommentSetting() !== 'disabled'; } @@ -670,8 +660,7 @@ protected function commentsEnabled() */ protected function listsEnabled() { - $check = $this->serviceLocator - ->get(\VuFind\Config\AccountCapabilities::class); + $check = $this->getService(\VuFind\Config\AccountCapabilities::class); return $check->getListSetting() !== 'disabled'; } @@ -682,8 +671,7 @@ protected function listsEnabled() */ protected function tagsEnabled() { - $check = $this->serviceLocator - ->get(\VuFind\Config\AccountCapabilities::class); + $check = $this->getService(\VuFind\Config\AccountCapabilities::class); return $check->getTagSetting() !== 'disabled'; } @@ -817,7 +805,7 @@ protected function clearFollowupUrl() */ protected function getRecordTabManager() { - return $this->serviceLocator->get(\VuFind\RecordTab\TabManager::class); + return $this->getService(\VuFind\RecordTab\TabManager::class); } /** diff --git a/module/VuFind/src/VuFind/Controller/AbstractRecord.php b/module/VuFind/src/VuFind/Controller/AbstractRecord.php index 0dc73e9b355..2c78c89efd3 100644 --- a/module/VuFind/src/VuFind/Controller/AbstractRecord.php +++ b/module/VuFind/src/VuFind/Controller/AbstractRecord.php @@ -167,7 +167,7 @@ public function addcommentAction() // something has gone wrong (or user submitted blank form) and we // should do nothing: if (!empty($comment)) { - $populator = $this->serviceLocator->get(ResourcePopulator::class); + $populator = $this->getService(ResourcePopulator::class); $resource = $populator->getOrCreateResourceForDriver($driver); $commentsService = $this->getDbService( \VuFind\Db\Service\CommentsServiceInterface::class @@ -179,7 +179,7 @@ public function addcommentAction() $driver->isRatingAllowed() && '0' !== ($rating = $this->params()->fromPost('rating', '0')) ) { - $ratingsService = $this->serviceLocator->get(RatingsService::class); + $ratingsService = $this->getService(RatingsService::class); $ratingsService->saveRating($driver, $user->getId(), intval($rating)); } @@ -241,7 +241,7 @@ public function addtagAction() // Save tags, if any: if ($tags = $this->params()->fromPost('tag')) { - $this->serviceLocator->get(TagsService::class)->linkTagsToRecord($driver, $user, $tags); + $this->getService(TagsService::class)->linkTagsToRecord($driver, $user, $tags); $this->flashMessenger()->addMessage(['msg' => 'add_tag_success'], 'success'); return $this->redirectToRecord(); } @@ -274,7 +274,7 @@ public function deletetagAction() // Delete tags, if any: if ($tag = $this->params()->fromPost('tag')) { - $this->serviceLocator->get(TagsService::class)->unlinkTagsFromRecord( + $this->getService(TagsService::class)->unlinkTagsFromRecord( $driver, $user, [$tag] @@ -315,7 +315,7 @@ public function ratingAction() ) { throw new BadRequestException('error_inconsistent_parameters'); } - $ratingsService = $this->serviceLocator->get(RatingsService::class); + $ratingsService = $this->getService(RatingsService::class); $ratingsService->saveRating( $driver, $user->getId(), @@ -330,7 +330,7 @@ public function ratingAction() // Display the "add rating" form: $currentRating = $user - ? $this->serviceLocator->get(RatingsService::class)->getRatingData($driver, $user->getId()) + ? $this->getService(RatingsService::class)->getRatingData($driver, $user->getId()) : null; return $this->createViewModel(compact('currentRating')); } @@ -412,9 +412,9 @@ protected function processSave() // Perform the save operation: $driver = $this->loadRecord(); $post = $this->getRequest()->getPost()->toArray(); - $tagsService = $this->serviceLocator->get(TagsService::class); + $tagsService = $this->getService(TagsService::class); $post['mytags'] = $tagsService->parse($post['mytags'] ?? ''); - $favorites = $this->serviceLocator->get(\VuFind\Favorites\FavoritesService::class); + $favorites = $this->getService(\VuFind\Favorites\FavoritesService::class); $results = $favorites->saveRecordToFavorites($post, $user, $driver); // Display a success status message: @@ -541,7 +541,7 @@ public function emailAction() $driver = $this->loadRecord(); // Create view - $mailer = $this->serviceLocator->get(\VuFind\Mailer\Mailer::class); + $mailer = $this->getService(\VuFind\Mailer\Mailer::class); $view = $this->createEmailViewModel( null, $mailer->getDefaultRecordSubject($driver) @@ -584,8 +584,7 @@ public function emailAction() */ protected function smsEnabled() { - $check = $this->serviceLocator - ->get(\VuFind\Config\AccountCapabilities::class); + $check = $this->getService(\VuFind\Config\AccountCapabilities::class); return $check->getSmsSetting() !== 'disabled'; } @@ -605,7 +604,7 @@ public function smsAction() $driver = $this->loadRecord(); // Load the SMS carrier list: - $sms = $this->serviceLocator->get(\VuFind\SMS\SMSInterface::class); + $sms = $this->getService(\VuFind\SMS\SMSInterface::class); $view = $this->createViewModel(); $view->carriers = $sms->getCarriers(); $view->validation = $sms->getValidationType(); @@ -617,7 +616,7 @@ public function smsAction() // Process form submission: if ($this->formWasSubmitted(useCaptcha: $view->useCaptcha)) { // Do CSRF check - $csrf = $this->serviceLocator->get(\VuFind\Validator\SessionCsrf::class); + $csrf = $this->getService(\VuFind\Validator\SessionCsrf::class); if (!$csrf->isValid($this->getRequest()->getPost()->get('csrf'))) { throw new \VuFind\Exception\BadRequest( 'error_inconsistent_parameters' @@ -679,7 +678,7 @@ public function exportAction() $format = $this->params()->fromQuery('style'); // Display export menu if missing/invalid option - $export = $this->serviceLocator->get(\VuFind\Export::class); + $export = $this->getService(\VuFind\Export::class); if (empty($format) || !$export->recordSupportsFormat($driver, $format)) { if (!empty($format)) { $this->flashMessenger() @@ -768,8 +767,7 @@ public function explainAction() return $view; } - $explanation = $this->serviceLocator - ->get(\VuFind\Search\Explanation\PluginManager::class) + $explanation = $this->getService(\VuFind\Search\Explanation\PluginManager::class) ->get($record->getSourceIdentifier()); $params = $explanation->getParams(); diff --git a/module/VuFind/src/VuFind/Controller/AbstractSearch.php b/module/VuFind/src/VuFind/Controller/AbstractSearch.php index 0fd05947439..12afa219ffe 100644 --- a/module/VuFind/src/VuFind/Controller/AbstractSearch.php +++ b/module/VuFind/src/VuFind/Controller/AbstractSearch.php @@ -115,8 +115,7 @@ public function advancedAction() // If we have default filters, set them up as a fake "saved" search // to properly populate special controls on the advanced screen. if (!$view->saved && count($view->options->getDefaultFilters()) > 0) { - $view->saved = $this->serviceLocator - ->get(\VuFind\Search\Results\PluginManager::class) + $view->saved = $this->getService(\VuFind\Search\Results\PluginManager::class) ->get($this->searchClassId); $view->saved->getParams()->initFromRequest( new \Laminas\Stdlib\Parameters([]) @@ -234,8 +233,7 @@ protected function getSearchSetupCallback() return null; } - $rManager = $this->serviceLocator - ->get(\VuFind\Recommend\PluginManager::class); + $rManager = $this->getService(\VuFind\Recommend\PluginManager::class); $override = $this->params()->fromQuery('recommendOverride'); @@ -269,7 +267,7 @@ protected function getSearchSetupCallback() */ public function homeAction() { - $blocks = $this->serviceLocator->get(\VuFind\ContentBlock\BlockLoader::class) + $blocks = $this->getService(\VuFind\ContentBlock\BlockLoader::class) ->getFromSearchClassId($this->searchClassId); return $this->createViewModel(compact('blocks')); } @@ -325,7 +323,7 @@ protected function getRssSearchResponse(ViewModel $view): Response $writer->render(); // Apply XSLT if we can find a relevant file: - $themeInfo = $this->serviceLocator->get(\VuFindTheme\ThemeInfo::class); + $themeInfo = $this->getService(\VuFindTheme\ThemeInfo::class); $themeHits = $themeInfo->findInThemes('assets/xsl/rss.xsl'); if ($themeHits) { $xsl = $this->url()->fromRoute('home') . 'themes/' @@ -364,7 +362,7 @@ protected function getSearchResultsView($setupCallback = null) return $this->redirectToSavedSearch($savedId); } - $runner = $this->serviceLocator->get(\VuFind\Search\SearchRunner::class); + $runner = $this->getService(\VuFind\Search\SearchRunner::class); // Send both GET and POST variables to search class: $request = $this->getRequest()->getQuery()->toArray() @@ -437,9 +435,7 @@ protected function getSearchResultsView($setupCallback = null) } // Schedule options for footer tools - $view->scheduleOptions = $this->serviceLocator - ->get(\VuFind\Search\History::class) - ->getScheduleOptions(); + $view->scheduleOptions = $this->getService(\VuFind\Search\History::class)->getScheduleOptions(); $view->saveToHistory = $this->saveToHistory; return $view; } @@ -522,7 +518,7 @@ protected function getRedirectForRecord( */ protected function retrieveSearchSecurely($searchId) { - $sessId = $this->serviceLocator->get(SessionManager::class)->getId(); + $sessId = $this->getService(SessionManager::class)->getId(); return $this->getDbService(SearchServiceInterface::class) ->getSearchByIdAndOwner($searchId, $sessId, $this->getUser()); } @@ -536,8 +532,8 @@ protected function retrieveSearchSecurely($searchId) */ protected function saveSearchToHistory($results) { - $sessId = $this->serviceLocator->get(SessionManager::class)->getId(); - $this->serviceLocator->get(\VuFind\Search\SearchNormalizer::class)->saveNormalizedSearch( + $sessId = $this->getService(SessionManager::class)->getId(); + $this->getService(\VuFind\Search\SearchNormalizer::class)->saveNormalizedSearch( $results, $sessId, $this->getUser()?->getId() @@ -589,8 +585,7 @@ protected function restoreAdvancedSearch($searchId) */ protected function getResultsManager() { - return $this->serviceLocator - ->get(\VuFind\Search\Results\PluginManager::class); + return $this->getService(\VuFind\Search\Results\PluginManager::class); } /** @@ -648,7 +643,7 @@ protected function getRangeSettings($fields, $type, $savedSearch = false) */ protected function getRangeFieldList($config, $section, $filter) { - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class) + $config = $this->getService(\VuFind\Config\PluginManager::class) ->get($config); $fields = isset($config->SpecialFacets->$section) ? $config->SpecialFacets->$section->toArray() : []; @@ -820,7 +815,7 @@ protected function processAdvancedCheckboxes($params, $savedSearch = false) $section = $params[1] ?? 'CheckboxFacets'; // Load config file: - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class) + $config = $this->getService(\VuFind\Config\PluginManager::class) ->get($config); // Process checkbox settings in config: @@ -891,7 +886,7 @@ public function facetListAction() ? 'count' : current(array_keys($facetSortOptions)); } - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class) + $config = $this->getService(\VuFind\Config\PluginManager::class) ->get($options->getFacetsIni()); $limit = $config->Results_Settings->lightboxLimit ?? 50; $limit = $this->params()->fromQuery('facetlimit', $limit); @@ -941,8 +936,6 @@ public function facetListAction() */ public function getOptionsForClass(): \VuFind\Search\Base\Options { - return $this->serviceLocator - ->get(\VuFind\Search\Options\PluginManager::class) - ->get($this->searchClassId); + return $this->getService(\VuFind\Search\Options\PluginManager::class)->get($this->searchClassId); } } diff --git a/module/VuFind/src/VuFind/Controller/AbstractSolrSearch.php b/module/VuFind/src/VuFind/Controller/AbstractSolrSearch.php index f5f55ec324c..6e9ab35e8e9 100644 --- a/module/VuFind/src/VuFind/Controller/AbstractSolrSearch.php +++ b/module/VuFind/src/VuFind/Controller/AbstractSolrSearch.php @@ -58,8 +58,7 @@ class AbstractSolrSearch extends AbstractSearch */ protected function addFacetDetailsToView(ViewModel $view, $list = 'Advanced'): void { - $facets = $this->serviceLocator - ->get(\VuFind\Search\FacetCache\PluginManager::class) + $facets = $this->getService(\VuFind\Search\FacetCache\PluginManager::class) ->get($this->searchClassId) ->getList($list); $view->hierarchicalFacets @@ -172,8 +171,7 @@ protected function processAdvancedFacets( if (in_array($facet, $hierarchicalFacets)) { // Process the facets if (!$facetHelper) { - $facetHelper = $this->serviceLocator - ->get(\VuFind\Search\Solr\HierarchicalFacetHelper::class); + $facetHelper = $this->getService(\VuFind\Search\Solr\HierarchicalFacetHelper::class); $options = $this->getOptionsForClass(); } diff --git a/module/VuFind/src/VuFind/Controller/AlmaController.php b/module/VuFind/src/VuFind/Controller/AlmaController.php index 7e0128d0c79..d4e4ac9a6e7 100644 --- a/module/VuFind/src/VuFind/Controller/AlmaController.php +++ b/module/VuFind/src/VuFind/Controller/AlmaController.php @@ -284,7 +284,7 @@ protected function webhookUser($requestBodyJson) $user = $this->userService->getUserByCatId($primaryId); if ($user) { try { - $this->serviceLocator->get(UserAccountService::class)->purgeUserData($user); + $this->getService(UserAccountService::class)->purgeUserData($user); $jsonResponse = $this->createJsonResponse( 'Successfully deleted user with primary ID \'' . $primaryId . '\' in VuFind.', @@ -377,7 +377,7 @@ protected function sendSetPasswordEmail(UserEntityInterface $user, $config) ] ); // Send the email - $this->serviceLocator->get(\VuFind\Mailer\Mailer::class)->send( + $this->getService(\VuFind\Mailer\Mailer::class)->send( $user->getEmail(), $config->Site->email, $this->translate( diff --git a/module/VuFind/src/VuFind/Controller/AuthorController.php b/module/VuFind/src/VuFind/Controller/AuthorController.php index 2926307c5b3..1ab60b9b7e0 100644 --- a/module/VuFind/src/VuFind/Controller/AuthorController.php +++ b/module/VuFind/src/VuFind/Controller/AuthorController.php @@ -108,8 +108,7 @@ public function homeAction() */ protected function resultScrollerActive() { - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class) - ->get('config'); + $config = $this->getService(\VuFind\Config\PluginManager::class)->get('config'); return $config->Record->next_prev_navigation ?? false; } } diff --git a/module/VuFind/src/VuFind/Controller/BlenderController.php b/module/VuFind/src/VuFind/Controller/BlenderController.php index 2255f80fbc2..29fa804a6df 100644 --- a/module/VuFind/src/VuFind/Controller/BlenderController.php +++ b/module/VuFind/src/VuFind/Controller/BlenderController.php @@ -60,8 +60,7 @@ public function __construct(ServiceLocatorInterface $sm) */ protected function resultScrollerActive() { - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class) - ->get('config'); + $config = $this->getService(\VuFind\Config\PluginManager::class)->get('config'); return $config->Record->next_prev_navigation ?? false; } } diff --git a/module/VuFind/src/VuFind/Controller/BrowseController.php b/module/VuFind/src/VuFind/Controller/BrowseController.php index 5094d414fe9..687ff898aee 100644 --- a/module/VuFind/src/VuFind/Controller/BrowseController.php +++ b/module/VuFind/src/VuFind/Controller/BrowseController.php @@ -331,7 +331,7 @@ public function tagAction() if ($this->params()->fromQuery('findby')) { $params = $this->getRequest()->getQuery()->toArray(); - $tagsService = $this->serviceLocator->get(TagsService::class); + $tagsService = $this->getService(TagsService::class); // Special case -- display alphabet selection if necessary: if ($params['findby'] == 'alphabetical') { $legalLetters = $this->getAlphabetList(); @@ -633,8 +633,7 @@ protected function getFacetList( $sort = 'count', $query = '[* TO *]' ) { - $results = $this->serviceLocator - ->get(\VuFind\Search\Results\PluginManager::class)->get('Solr'); + $results = $this->getService(\VuFind\Search\Results\PluginManager::class)->get('Solr'); $params = $results->getParams(); $params->addFacet($facet); if ($category != null) { diff --git a/module/VuFind/src/VuFind/Controller/CartController.php b/module/VuFind/src/VuFind/Controller/CartController.php index 8b9ada4f12e..218caed8526 100644 --- a/module/VuFind/src/VuFind/Controller/CartController.php +++ b/module/VuFind/src/VuFind/Controller/CartController.php @@ -103,7 +103,7 @@ public function __construct( */ protected function getCart() { - return $this->serviceLocator->get(\VuFind\Cart::class); + return $this->getService(\VuFind\Cart::class); } /** @@ -316,7 +316,7 @@ public function emailAction() // Attempt to send the email and show an appropriate flash message: try { // If we got this far, we're ready to send the email: - $mailer = $this->serviceLocator->get(\VuFind\Mailer\Mailer::class); + $mailer = $this->getService(\VuFind\Mailer\Mailer::class); $mailer->setMaxRecipients($view->maxRecipients); $cc = $this->params()->fromPost('ccself') && $view->from != $view->to ? $view->from : null; @@ -533,7 +533,7 @@ public function saveAction() // Process submission if necessary: if (!($submitDisabled ?? false) && $this->formWasSubmitted()) { - $results = $this->serviceLocator->get(FavoritesService::class) + $results = $this->getService(FavoritesService::class) ->saveRecordsToFavorites($this->getRequest()->getPost()->toArray(), $user); $listUrl = $this->url()->fromRoute( 'userList', diff --git a/module/VuFind/src/VuFind/Controller/CollectionController.php b/module/VuFind/src/VuFind/Controller/CollectionController.php index 7e22a4787ba..9f68242cbec 100644 --- a/module/VuFind/src/VuFind/Controller/CollectionController.php +++ b/module/VuFind/src/VuFind/Controller/CollectionController.php @@ -105,8 +105,7 @@ protected function showTab($tab, $ajax = false) */ protected function resultScrollerActive() { - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class) - ->get('config'); + $config = $this->getService(\VuFind\Config\PluginManager::class)->get('config'); return $config->Record->next_prev_navigation ?? false; } } diff --git a/module/VuFind/src/VuFind/Controller/CollectionsController.php b/module/VuFind/src/VuFind/Controller/CollectionsController.php index 9f9c3293b75..641d842aa3d 100644 --- a/module/VuFind/src/VuFind/Controller/CollectionsController.php +++ b/module/VuFind/src/VuFind/Controller/CollectionsController.php @@ -180,8 +180,7 @@ protected function showBrowseIndex() $browseField = 'hierarchy_browse'; - $searchObject = $this->serviceLocator - ->get(\VuFind\Search\Results\PluginManager::class)->get('Solr'); + $searchObject = $this->getService(\VuFind\Search\Results\PluginManager::class)->get('Solr'); foreach ($appliedFilters as $filter) { $searchObject->getParams()->addFilter($filter); } @@ -348,7 +347,7 @@ protected function getCollectionsFromTitle($title) { $title = addcslashes($title, '"'); $query = new Query("is_hierarchy_title:\"$title\"", 'AllFields'); - $searchService = $this->serviceLocator->get(\VuFindSearch\Service::class); + $searchService = $this->getService(\VuFindSearch\Service::class); $command = new SearchCommand( 'Solr', $query, diff --git a/module/VuFind/src/VuFind/Controller/CombinedController.php b/module/VuFind/src/VuFind/Controller/CombinedController.php index 2a9bf18ac36..d1ac850bf07 100644 --- a/module/VuFind/src/VuFind/Controller/CombinedController.php +++ b/module/VuFind/src/VuFind/Controller/CombinedController.php @@ -73,7 +73,7 @@ public function homeAction() { // We need to load blocks differently in this controller since it // doesn't follow the usual configuration pattern. - $blocks = $this->serviceLocator->get(\VuFind\ContentBlock\BlockLoader::class) + $blocks = $this->getService(\VuFind\ContentBlock\BlockLoader::class) ->getFromConfig('combined'); return $this->createViewModel(compact('blocks')); } @@ -92,7 +92,7 @@ public function resultAction() // Validate configuration: $sectionId = $this->params()->fromQuery('id'); - $optionsManager = $this->serviceLocator->get(\VuFind\Search\Options\PluginManager::class); + $optionsManager = $this->getService(\VuFind\Search\Options\PluginManager::class); $combinedOptions = $optionsManager->get('combined'); $tabConfig = $combinedOptions->getTabConfig(); if (!isset($tabConfig[$sectionId])) { @@ -147,7 +147,7 @@ public function resultsAction() // Set up current request context: $request = $this->getRequest()->getQuery()->toArray() + $this->getRequest()->getPost()->toArray(); - $results = $this->serviceLocator->get(SearchRunner::class)->run( + $results = $this->getService(SearchRunner::class)->run( $request, 'Combined', $this->getSearchSetupCallback() @@ -160,7 +160,7 @@ public function resultsAction() // Gather combined results: $combinedResults = []; - $optionsManager = $this->serviceLocator->get(\VuFind\Search\Options\PluginManager::class); + $optionsManager = $this->getService(\VuFind\Search\Options\PluginManager::class); $combinedOptions = $optionsManager->get('combined'); // Save the initial type value, since it may get manipulated below: $initialType = $this->params()->fromQuery('type'); @@ -201,7 +201,7 @@ public function resultsAction() $results->performAndProcessSearch(); $actualMaxColumns = count($combinedResults); - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class)->get('combined')->toArray(); + $config = $this->getService(\VuFind\Config\PluginManager::class)->get('combined')->toArray(); $columnConfig = intval($config['Layout']['columns'] ?? $actualMaxColumns); $columns = min($columnConfig, $actualMaxColumns); $placement = $config['Layout']['stack_placement'] ?? 'distributed'; @@ -212,7 +212,7 @@ public function resultsAction() // Identify if any modules use include_recommendations_side or // include_recommendations_noresults_side. $columnSideRecommendations = []; - $recommendationManager = $this->serviceLocator->get(\VuFind\Recommend\PluginManager::class); + $recommendationManager = $this->getService(\VuFind\Recommend\PluginManager::class); foreach ($config as $subconfig) { foreach (['include_recommendations_side', 'include_recommendations_noresults_side'] as $type) { if (is_array($subconfig[$type] ?? false)) { @@ -261,8 +261,7 @@ public function searchboxAction() // We don't need to pass activeSearchClassId forward: unset($params['activeSearchClassId']); - $route = $this->serviceLocator - ->get(\VuFind\Search\Options\PluginManager::class) + $route = $this->getService(\VuFind\Search\Options\PluginManager::class) ->get($searchClassId)->getSearchAction(); $base = $this->url()->fromRoute($route); return $this->redirect() diff --git a/module/VuFind/src/VuFind/Controller/ContentController.php b/module/VuFind/src/VuFind/Controller/ContentController.php index 83c3abf8108..b5f4ed78d22 100644 --- a/module/VuFind/src/VuFind/Controller/ContentController.php +++ b/module/VuFind/src/VuFind/Controller/ContentController.php @@ -81,7 +81,7 @@ public function contentAction() } $page = substr($page, $p + 1); } - $pageLocator = $this->serviceLocator->get(\VuFind\Content\PageLocator::class); + $pageLocator = $this->getService(\VuFind\Content\PageLocator::class); $data = $pageLocator->determineTemplateAndRenderer($pathPrefix, $page); $method = isset($data) ? 'getViewFor' . ucwords($data['renderer']) : false; diff --git a/module/VuFind/src/VuFind/Controller/EITController.php b/module/VuFind/src/VuFind/Controller/EITController.php index 33158901783..9d6584e571f 100644 --- a/module/VuFind/src/VuFind/Controller/EITController.php +++ b/module/VuFind/src/VuFind/Controller/EITController.php @@ -61,8 +61,7 @@ public function __construct(ServiceLocatorInterface $sm) */ protected function resultScrollerActive() { - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class) - ->get('EIT'); + $config = $this->getService(\VuFind\Config\PluginManager::class)->get('EIT'); return $config->Record->next_prev_navigation ?? false; } diff --git a/module/VuFind/src/VuFind/Controller/EITrecordController.php b/module/VuFind/src/VuFind/Controller/EITrecordController.php index 783d1268b88..4977e937c6f 100644 --- a/module/VuFind/src/VuFind/Controller/EITrecordController.php +++ b/module/VuFind/src/VuFind/Controller/EITrecordController.php @@ -68,8 +68,7 @@ public function __construct(ServiceLocatorInterface $sm) */ protected function resultScrollerActive() { - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class) - ->get('EIT'); + $config = $this->getService(\VuFind\Config\PluginManager::class)->get('EIT'); return $config->Record->next_prev_navigation ?? false; } } diff --git a/module/VuFind/src/VuFind/Controller/EdsController.php b/module/VuFind/src/VuFind/Controller/EdsController.php index a825c704632..3b068a3918b 100644 --- a/module/VuFind/src/VuFind/Controller/EdsController.php +++ b/module/VuFind/src/VuFind/Controller/EdsController.php @@ -63,8 +63,7 @@ public function __construct(ServiceLocatorInterface $sm) */ protected function resultScrollerActive() { - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class) - ->get('EDS'); + $config = $this->getService(\VuFind\Config\PluginManager::class)->get('EDS'); return $config->Record->next_prev_navigation ?? false; } diff --git a/module/VuFind/src/VuFind/Controller/EdsrecordController.php b/module/VuFind/src/VuFind/Controller/EdsrecordController.php index 9351535c913..13f37e342e5 100644 --- a/module/VuFind/src/VuFind/Controller/EdsrecordController.php +++ b/module/VuFind/src/VuFind/Controller/EdsrecordController.php @@ -125,8 +125,7 @@ public function pdfAction() */ protected function resultScrollerActive() { - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class) - ->get('EDS'); + $config = $this->getService(\VuFind\Config\PluginManager::class)->get('EDS'); return $config->Record->next_prev_navigation ?? false; } } diff --git a/module/VuFind/src/VuFind/Controller/ExternalAuthController.php b/module/VuFind/src/VuFind/Controller/ExternalAuthController.php index 6236857e750..91eab29f8ef 100644 --- a/module/VuFind/src/VuFind/Controller/ExternalAuthController.php +++ b/module/VuFind/src/VuFind/Controller/ExternalAuthController.php @@ -69,12 +69,11 @@ public function ezproxyLoginAction() $user = $this->getUser(); - $authService = $this->serviceLocator - ->get(\LmcRbacMvc\Service\AuthorizationService::class); + $authService = $this->getService(\LmcRbacMvc\Service\AuthorizationService::class); if ($authService->isGranted($this->ezproxyRequiredPermission)) { // Access granted, redirect to EZproxy if (empty($config->EZproxy->disable_ticket_auth_logging)) { - $logger = $this->serviceLocator->get(\VuFind\Log\Logger::class); + $logger = $this->getService(\VuFind\Log\Logger::class); $logger->info( "EZproxy login to '" . $config->EZproxy->host . "' for '" . ($user ? $user->getUsername() : 'anonymous') diff --git a/module/VuFind/src/VuFind/Controller/Feature/AlphaBrowseTrait.php b/module/VuFind/src/VuFind/Controller/Feature/AlphaBrowseTrait.php index 6b6b566e2d4..af0de1c8ef7 100644 --- a/module/VuFind/src/VuFind/Controller/Feature/AlphaBrowseTrait.php +++ b/module/VuFind/src/VuFind/Controller/Feature/AlphaBrowseTrait.php @@ -59,7 +59,7 @@ trait AlphaBrowseTrait */ protected function alphabeticBrowse() { - $service = $this->serviceLocator->get(\VuFindSearch\Service::class); + $service = $this->getService(\VuFindSearch\Service::class); $command = new AlphabeticBrowseCommand( $this->alphabrowseBackend, ...func_get_args() diff --git a/module/VuFind/src/VuFind/Controller/Feature/ConfigPathTrait.php b/module/VuFind/src/VuFind/Controller/Feature/ConfigPathTrait.php index 804b4d8cb7b..11902fadbe7 100644 --- a/module/VuFind/src/VuFind/Controller/Feature/ConfigPathTrait.php +++ b/module/VuFind/src/VuFind/Controller/Feature/ConfigPathTrait.php @@ -49,7 +49,7 @@ trait ConfigPathTrait */ protected function getBaseConfigFilePath(string $filename): string { - $resolver = $this->serviceLocator->get(\VuFind\Config\PathResolver::class); + $resolver = $this->getService(\VuFind\Config\PathResolver::class); return $resolver->getBaseConfigPath($filename); } @@ -62,7 +62,7 @@ protected function getBaseConfigFilePath(string $filename): string */ protected function getForcedLocalConfigPath(string $filename): string { - $resolver = $this->serviceLocator->get(\VuFind\Config\PathResolver::class); + $resolver = $this->getService(\VuFind\Config\PathResolver::class); return $resolver->getLocalConfigPath($filename, null, true); } } diff --git a/module/VuFind/src/VuFind/Controller/Feature/RecordVersionsSearchTrait.php b/module/VuFind/src/VuFind/Controller/Feature/RecordVersionsSearchTrait.php index 84bded8fa21..c17d531a005 100644 --- a/module/VuFind/src/VuFind/Controller/Feature/RecordVersionsSearchTrait.php +++ b/module/VuFind/src/VuFind/Controller/Feature/RecordVersionsSearchTrait.php @@ -73,7 +73,7 @@ public function versionsAction() $view = $this->getSearchResultsView($callback); if (null !== $id) { - $loader = $this->serviceLocator->get(\VuFind\Record\Loader::class); + $loader = $this->getService(\VuFind\Record\Loader::class); $view->driver = $loader->load($id, $this->searchClassId); } return $view; diff --git a/module/VuFind/src/VuFind/Controller/FeedbackController.php b/module/VuFind/src/VuFind/Controller/FeedbackController.php index b01fbf66983..7455718fcea 100644 --- a/module/VuFind/src/VuFind/Controller/FeedbackController.php +++ b/module/VuFind/src/VuFind/Controller/FeedbackController.php @@ -67,7 +67,7 @@ public function formAction() $user = $this->getUser(); - $form = $this->serviceLocator->get($this->formClass); + $form = $this->getService($this->formClass); $prefill = $this->params()->fromQuery(); $params = []; if ($refererHeader = $this->getRequest()->getHeader('Referer')) { diff --git a/module/VuFind/src/VuFind/Controller/HierarchyController.php b/module/VuFind/src/VuFind/Controller/HierarchyController.php index d8971651b1e..d449fe2d35a 100644 --- a/module/VuFind/src/VuFind/Controller/HierarchyController.php +++ b/module/VuFind/src/VuFind/Controller/HierarchyController.php @@ -122,8 +122,7 @@ public function searchtreeAction(): ResponseInterface $lookfor = $this->params()->fromQuery('lookfor', ''); $searchType = $this->params()->fromQuery('type', 'AllFields'); - $results = $this->serviceLocator - ->get(\VuFind\Search\Results\PluginManager::class)->get($source); + $results = $this->getService(\VuFind\Search\Results\PluginManager::class)->get($source); $results->getParams()->setBasicSearch($lookfor, $searchType); $results->getParams()->addFilter('hierarchy_top_id:' . $hierarchyID); $facets = $results->getFullFieldFacets(['id'], false, null === $limit ? -1 : $limit + 1); diff --git a/module/VuFind/src/VuFind/Controller/HoldsController.php b/module/VuFind/src/VuFind/Controller/HoldsController.php index 61088483cb3..83277c7c90c 100644 --- a/module/VuFind/src/VuFind/Controller/HoldsController.php +++ b/module/VuFind/src/VuFind/Controller/HoldsController.php @@ -467,7 +467,7 @@ protected function getHoldUpdateResultsContainer() { return new \Laminas\Session\Container( 'hold_update', - $this->serviceLocator->get(\Laminas\Session\SessionManager::class) + $this->getService(\Laminas\Session\SessionManager::class) ); } diff --git a/module/VuFind/src/VuFind/Controller/HoldsTrait.php b/module/VuFind/src/VuFind/Controller/HoldsTrait.php index 57e6d4b8780..ff06397c7cf 100644 --- a/module/VuFind/src/VuFind/Controller/HoldsTrait.php +++ b/module/VuFind/src/VuFind/Controller/HoldsTrait.php @@ -227,7 +227,7 @@ public function holdAction() } // Set default start date to today: - $dateConverter = $this->serviceLocator->get(\VuFind\Date\Converter::class); + $dateConverter = $this->getService(\VuFind\Date\Converter::class); $defaultStartDate = $dateConverter->convertToDisplayDate('U', time()); // Find and format the default required date: diff --git a/module/VuFind/src/VuFind/Controller/ILLRequestsTrait.php b/module/VuFind/src/VuFind/Controller/ILLRequestsTrait.php index b304a84dd7a..fe41d2f1d71 100644 --- a/module/VuFind/src/VuFind/Controller/ILLRequestsTrait.php +++ b/module/VuFind/src/VuFind/Controller/ILLRequestsTrait.php @@ -140,8 +140,7 @@ public function illRequestAction() // Find and format the default required date: $defaultRequiredDate = $this->ILLRequests() ->getDefaultRequiredDate($checkRequests); - $defaultRequiredDate - = $this->serviceLocator->get(\VuFind\Date\Converter::class) + $defaultRequiredDate = $this->getService(\VuFind\Date\Converter::class) ->convertToDisplayDate('U', $defaultRequiredDate); // Get pickup libraries diff --git a/module/VuFind/src/VuFind/Controller/InstallController.php b/module/VuFind/src/VuFind/Controller/InstallController.php index 405ce52e8d3..4da410720bb 100644 --- a/module/VuFind/src/VuFind/Controller/InstallController.php +++ b/module/VuFind/src/VuFind/Controller/InstallController.php @@ -157,7 +157,7 @@ protected function checkBasicConfig() */ protected function getSolrUrlFromImportConfig() { - $resolver = $this->serviceLocator->get(\VuFind\Config\PathResolver::class); + $resolver = $this->getService(\VuFind\Config\PathResolver::class); $importConfig = $resolver->getLocalConfigPath('import.properties', 'import'); if (file_exists($importConfig)) { $props = file_get_contents($importConfig); @@ -212,7 +212,7 @@ function_exists('posix_getpwuid') */ protected function checkCache() { - $cache = $this->serviceLocator->get(\VuFind\Cache\Manager::class); + $cache = $this->getService(\VuFind\Cache\Manager::class); return [ 'title' => 'Cache', 'status' => !$cache->hasDirectoryCreationError(), @@ -227,7 +227,7 @@ protected function checkCache() */ public function fixcacheAction() { - $cache = $this->serviceLocator->get(\VuFind\Cache\Manager::class); + $cache = $this->getService(\VuFind\Cache\Manager::class); $view = $this->createViewModel(); $view->cacheDir = $cache->getCacheDir(); if (function_exists('posix_getpwuid') && function_exists('posix_geteuid')) { @@ -413,8 +413,7 @@ public function fixdatabaseAction() try { $dbName = ($view->driver == 'pgsql') ? 'template1' : $view->driver; - $db = $this->serviceLocator - ->get(\VuFind\Db\AdapterFactory::class) + $db = $this->getService(\VuFind\Db\AdapterFactory::class) ->getAdapterFromConnectionString("{$connection}/{$dbName}"); } catch (\Exception $e) { $this->flashMessenger() @@ -451,8 +450,7 @@ public function fixdatabaseAction() foreach ($preCommands as $query) { $db->query($query, $db::QUERY_MODE_EXECUTE); } - $dbFactory = $this->serviceLocator - ->get(\VuFind\Db\AdapterFactory::class); + $dbFactory = $this->getService(\VuFind\Db\AdapterFactory::class); $db = $dbFactory->getAdapterFromConnectionString( $connection . '/' . $view->dbname ); @@ -650,7 +648,7 @@ public function fixilsAction() protected function testSearchService() { // Try to retrieve an arbitrary ID -- this will fail if Solr is down: - $searchService = $this->serviceLocator->get(\VuFindSearch\Service::class); + $searchService = $this->getService(\VuFindSearch\Service::class); $command = new RetrieveCommand('Solr', '1'); $searchService->invoke($command)->getResult(); } @@ -812,7 +810,7 @@ public function performsecurityfixAction() // Now we want to loop through the database and update passwords (if // necessary). - $ilsAuthenticator = $this->serviceLocator->get(\VuFind\Auth\ILSAuthenticator::class); + $ilsAuthenticator = $this->getService(\VuFind\Auth\ILSAuthenticator::class); $userRows = $this->getDbService(UserServiceInterface::class)->getInsecureRows(); if (count($userRows) > 0) { $bcrypt = new Bcrypt(); @@ -853,7 +851,7 @@ public function checkSslCerts() { // Try to retrieve an SSL URL; if we're misconfigured, it will fail. try { - $this->serviceLocator->get(\VuFindHttp\HttpService::class) + $this->getService(\VuFindHttp\HttpService::class) ->get('https://google.com'); $status = true; } catch (\VuFindHttp\Exception\RuntimeException $e) { diff --git a/module/VuFind/src/VuFind/Controller/LibGuidesAZController.php b/module/VuFind/src/VuFind/Controller/LibGuidesAZController.php index a5662a1c476..cde54d74365 100644 --- a/module/VuFind/src/VuFind/Controller/LibGuidesAZController.php +++ b/module/VuFind/src/VuFind/Controller/LibGuidesAZController.php @@ -62,8 +62,7 @@ public function __construct(ServiceLocatorInterface $sm) */ protected function resultScrollerActive() { - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class) - ->get('LibGuidesAZ'); + $config = $this->getService(\VuFind\Config\PluginManager::class)->get('LibGuidesAZ'); return $config->Record->next_prev_navigation ?? false; } } diff --git a/module/VuFind/src/VuFind/Controller/LibGuidesController.php b/module/VuFind/src/VuFind/Controller/LibGuidesController.php index 39454e2dfc8..e15ed4c6b41 100644 --- a/module/VuFind/src/VuFind/Controller/LibGuidesController.php +++ b/module/VuFind/src/VuFind/Controller/LibGuidesController.php @@ -60,8 +60,7 @@ public function __construct(ServiceLocatorInterface $sm) */ protected function resultScrollerActive() { - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class) - ->get('LibGuides'); + $config = $this->getService(\VuFind\Config\PluginManager::class)->get('LibGuides'); return $config->Record->next_prev_navigation ?? false; } } diff --git a/module/VuFind/src/VuFind/Controller/LibraryCardsController.php b/module/VuFind/src/VuFind/Controller/LibraryCardsController.php index 5ddc63f2523..a30261b8d53 100644 --- a/module/VuFind/src/VuFind/Controller/LibraryCardsController.php +++ b/module/VuFind/src/VuFind/Controller/LibraryCardsController.php @@ -325,8 +325,7 @@ protected function processEditLibraryCard($user) $info = $patron; $info['cardID'] = $id; $info['cardName'] = $cardName; - $emailAuthenticator = $this->serviceLocator - ->get(\VuFind\Auth\EmailAuthenticator::class); + $emailAuthenticator = $this->getService(\VuFind\Auth\EmailAuthenticator::class); $emailAuthenticator->sendAuthenticationLink( $info['email'], $info, @@ -366,8 +365,7 @@ protected function processEditLibraryCard($user) */ protected function processEmailLink($user, $hash) { - $emailAuthenticator = $this->serviceLocator - ->get(\VuFind\Auth\EmailAuthenticator::class); + $emailAuthenticator = $this->getService(\VuFind\Auth\EmailAuthenticator::class); try { $info = $emailAuthenticator->authenticate($hash); $cardService = $this->getDbService(UserCardServiceInterface::class); diff --git a/module/VuFind/src/VuFind/Controller/MyResearchController.php b/module/VuFind/src/VuFind/Controller/MyResearchController.php index f042578d365..d52b431b83d 100644 --- a/module/VuFind/src/VuFind/Controller/MyResearchController.php +++ b/module/VuFind/src/VuFind/Controller/MyResearchController.php @@ -448,8 +448,7 @@ public function logoutAction() */ protected function getSearchRowSecurely($searchId, $userId) { - $sessId = $this->serviceLocator - ->get(\Laminas\Session\SessionManager::class)->getId(); + $sessId = $this->getService(\Laminas\Session\SessionManager::class)->getId(); $search = $this->getDbService(SearchServiceInterface::class) ->getSearchByIdAndOwner($searchId, $sessId, $userId); if (empty($search)) { @@ -489,7 +488,7 @@ protected function getUserVerificationContainer() { return new \Laminas\Session\Container( 'user_verification', - $this->serviceLocator->get(\Laminas\Session\SessionManager::class) + $this->getService(\Laminas\Session\SessionManager::class) ); } @@ -505,8 +504,7 @@ protected function getUserVerificationContainer() protected function scheduleSearch(UserEntityInterface $user, $schedule, $sid) { // Fail if scheduled searches are disabled. - $scheduleOptions = $this->serviceLocator - ->get(\VuFind\Search\History::class) + $scheduleOptions = $this->getService(\VuFind\Search\History::class) ->getScheduleOptions(); if (!isset($scheduleOptions[$schedule])) { throw new ForbiddenException('Illegal schedule option: ' . $schedule); @@ -516,8 +514,7 @@ protected function scheduleSearch(UserEntityInterface $user, $schedule, $sid) $savedRow = $this->getSearchRowSecurely($sid, $userId); // In case the user has just logged in, let's deduplicate... - $sessId = $this->serviceLocator - ->get(\Laminas\Session\SessionManager::class)->getId(); + $sessId = $this->getService(\Laminas\Session\SessionManager::class)->getId(); $duplicateId = $this->isDuplicateOfSavedSearch( $savedRow, $sessId, @@ -554,13 +551,11 @@ protected function scheduleSearch(UserEntityInterface $user, $schedule, $sid) public function schedulesearchAction() { // Fail if saved searches or subscriptions are disabled. - $check = $this->serviceLocator - ->get(\VuFind\Config\AccountCapabilities::class); + $check = $this->getService(\VuFind\Config\AccountCapabilities::class); if ($check->getSavedSearchSetting() === 'disabled') { throw new ForbiddenException('Saved searches disabled.'); } - $scheduleOptions = $this->serviceLocator - ->get(\VuFind\Search\History::class) + $scheduleOptions = $this->getService(\VuFind\Search\History::class) ->getScheduleOptions(); if (empty($scheduleOptions)) { throw new ForbiddenException('Scheduled searches disabled.'); @@ -579,7 +574,7 @@ public function schedulesearchAction() // If the user has just logged in, the search might be a duplicate; if // so, let's switch to the pre-existing version instead. - $sessId = $this->serviceLocator->get(\Laminas\Session\SessionManager::class)->getId(); + $sessId = $this->getService(\Laminas\Session\SessionManager::class)->getId(); $duplicateId = $this->isDuplicateOfSavedSearch( $search, $sessId, @@ -595,7 +590,7 @@ public function schedulesearchAction() } // Now fetch all the results: - $resultsManager = $this->serviceLocator->get(\VuFind\Search\Results\PluginManager::class); + $resultsManager = $this->getService(\VuFind\Search\Results\PluginManager::class); $results = $search->getSearchObject()?->deminify($resultsManager); if (!$results) { throw new Exception("Problem getting search object from search {$search->getId()}."); @@ -624,7 +619,7 @@ protected function isDuplicateOfSavedSearch( if (!$rowToCheck) { return null; } - $normalizer = $this->serviceLocator->get(\VuFind\Search\SearchNormalizer::class); + $normalizer = $this->getService(\VuFind\Search\SearchNormalizer::class); $searchObject = $rowToCheck->getSearchObject(); if (!$searchObject) { throw new Exception("Problem getting search object from search {$rowToCheck->getId()}."); @@ -651,8 +646,7 @@ protected function isDuplicateOfSavedSearch( public function savesearchAction() { // Fail if saved searches are disabled. - $check = $this->serviceLocator - ->get(\VuFind\Config\AccountCapabilities::class); + $check = $this->getService(\VuFind\Config\AccountCapabilities::class); if ($check->getSavedSearchSetting() === 'disabled') { throw new ForbiddenException('Saved searches disabled.'); } @@ -675,8 +669,7 @@ public function savesearchAction() // the user clicks "save" before logging in, then logs in during the // save process, but has the same search already saved in their account). $searchService = $this->getDbService(SearchServiceInterface::class); - $sessId = $this->serviceLocator - ->get(\Laminas\Session\SessionManager::class)->getId(); + $sessId = $this->getService(\Laminas\Session\SessionManager::class)->getId(); $rowToCheck = $searchService->getSearchByIdAndOwner($id, $sessId, $user); $duplicateId = $this->isDuplicateOfSavedSearch( $rowToCheck, @@ -736,7 +729,7 @@ public function profileAction() if (' ** ' === $homeLibrary) { $homeLibrary = null; } - $this->serviceLocator->get(ILSAuthenticator::class)->updateUserHomeLibrary($user, $homeLibrary); + $this->getService(ILSAuthenticator::class)->updateUserHomeLibrary($user, $homeLibrary); $this->flashMessenger()->addMessage('profile_update', 'success'); } @@ -879,7 +872,7 @@ public function deleteAction() return $redirect; } } elseif ($this->formWasSubmitted()) { - $this->serviceLocator->get(FavoritesService::class) + $this->getService(FavoritesService::class) ->deleteFavorites($ids, $listID === null ? null : (int)$listID, $user); $this->flashMessenger()->addMessage('fav_delete_success', 'success'); return $this->redirect()->toUrl($newUrl); @@ -922,7 +915,7 @@ public function performDeleteFavorite($id, $source) } // Perform delete and send appropriate flash message: - $favoritesService = $this->serviceLocator->get(FavoritesService::class); + $favoritesService = $this->getService(FavoritesService::class); if (null !== $listID) { // ...Specific List $list = $this->getDbService(UserListServiceInterface::class)->getUserListById($listID); @@ -951,9 +944,8 @@ public function performDeleteFavorite($id, $source) protected function processEditSubmit(UserEntityInterface $user, $driver, $listID) { $lists = $this->params()->fromPost('lists', []); - $tagsService = $this->serviceLocator->get(\VuFind\Tags\TagsService::class); - $favorites = $this->serviceLocator - ->get(\VuFind\Favorites\FavoritesService::class); + $tagsService = $this->getService(\VuFind\Tags\TagsService::class); + $favorites = $this->getService(\VuFind\Favorites\FavoritesService::class); $didSomething = false; foreach ($lists as $list) { $tags = $this->params()->fromPost('tags' . $list); @@ -1017,7 +1009,7 @@ public function editAction() $userResourceService = $this->getDbService(UserResourceServiceInterface::class); $userResources = $userResourceService->getFavoritesForRecord($id, $source, $listID, $user); $savedData = []; - $favoritesService = $this->serviceLocator->get(FavoritesService::class); + $favoritesService = $this->getService(FavoritesService::class); foreach ($userResources as $current) { // There should always be list data based on the way we retrieve this result, but // check just to be on the safe side. @@ -1126,7 +1118,7 @@ public function mylistAction() // If we got this far, we just need to display the favorites: try { - $runner = $this->serviceLocator->get(\VuFind\Search\SearchRunner::class); + $runner = $this->getService(\VuFind\Search\SearchRunner::class); // We want to merge together GET, POST and route parameters to // initialize our search object: @@ -1135,8 +1127,7 @@ public function mylistAction() + ['id' => $this->params()->fromRoute('id')]; // Set up listener for recommendations: - $rManager = $this->serviceLocator - ->get(\VuFind\Recommend\PluginManager::class); + $rManager = $this->getService(\VuFind\Recommend\PluginManager::class); $setupCallback = function ($runner, $params, $searchId) use ($rManager) { $listener = new RecommendListener($rManager, $searchId); $listener->setConfig( @@ -1150,7 +1141,7 @@ public function mylistAction() if ($this->listTagsEnabled()) { if ($list = $results->getListObject()) { - $tags = $this->serviceLocator->get(TagsService::class)->getListTags($list, $list->getUser()); + $tags = $this->getService(TagsService::class)->getListTags($list, $list->getUser()); foreach ($tags as $tag) { $listTags[$tag['id']] = $tag['tag']; } @@ -1183,7 +1174,7 @@ protected function processEditList(UserEntityInterface $user, $list) { // Process form within a try..catch so we can handle errors appropriately: try { - $favoritesService = $this->serviceLocator->get(FavoritesService::class); + $favoritesService = $this->getService(FavoritesService::class); $finalId = $favoritesService->updateListFromRequest($list, $user, $this->getRequest()->getPost()); // If the user is in the process of saving a record, send them back @@ -1253,7 +1244,7 @@ public function editlistAction() $newList = ($id == 'NEW'); // If this is a new list, use the FavoritesService to pre-populate some values in // a fresh object; if it's an existing list, we can just fetch from the database. - $favoritesService = $this->serviceLocator->get(FavoritesService::class); + $favoritesService = $this->getService(FavoritesService::class); $list = $newList ? $favoritesService->createListForUser($user) : $this->getDbService(UserListServiceInterface::class)->getUserListById($id); @@ -1272,7 +1263,7 @@ public function editlistAction() $listTags = null; if ($this->listTagsEnabled() && !$newList) { - $tagsService = $this->serviceLocator->get(TagsService::class); + $tagsService = $this->getService(TagsService::class); $listTags = $favoritesService ->formatTagStringForEditing($tagsService->getListTags($list, $list->getUser())); } @@ -1337,7 +1328,7 @@ public function deletelistAction() if ($confirm) { try { $list = $this->getDbService(UserListServiceInterface::class)->getUserListById($listID); - $this->serviceLocator->get(FavoritesService::class)->destroyList($list, $this->getUser()); + $this->getService(FavoritesService::class)->destroyList($list, $this->getUser()); // Success Message $this->flashMessenger()->addMessage('fav_list_delete', 'success'); @@ -1537,7 +1528,7 @@ public function checkedoutAction() $this->getRequest()->getPost(), $catalog, $patron, - $this->serviceLocator->get(CsrfInterface::class) + $this->getService(CsrfInterface::class) ) : []; @@ -1674,7 +1665,7 @@ public function finesAction() } if ($driversNeeded) { - $recordLoader = $this->serviceLocator->get(\VuFind\Record\Loader::class); + $recordLoader = $this->getService(\VuFind\Record\Loader::class); $drivers = $recordLoader->loadBatch($driversNeeded, true); foreach ($drivers as $i => $driver) { $fines[$i]['driver'] = $driver; @@ -1691,7 +1682,7 @@ public function finesAction() if (!empty($this->getConfig()->Authentication->enableAjax)) { $accountStatus = $this->getFineSummary( $fines, - $this->serviceLocator->get(\VuFind\Service\CurrencyFormatter::class) + $this->getService(\VuFind\Service\CurrencyFormatter::class) ); } else { $accountStatus = null; @@ -1789,7 +1780,7 @@ protected function sendRecoveryEmail(UserEntityInterface $user, $config) . $user->getVerifyHash() . '&auth_method=' . $method, ] ); - $this->serviceLocator->get(Mailer::class)->send( + $this->getService(Mailer::class)->send( $user->getEmail(), $config->Site->email, $this->translate('recovery_email_subject'), @@ -1850,7 +1841,7 @@ protected function sendChangeNotificationEmail($user, $newEmail) ); // If the user is setting up a new account, use the main email // address; if they have a pending address change, use that. - $this->serviceLocator->get(Mailer::class)->send( + $this->getService(Mailer::class)->send( $user->getEmail(), $config->Site->email, $this->translate('change_notification_email_subject'), @@ -1900,7 +1891,7 @@ protected function sendVerificationEmail($user, $change = false) // If the user is setting up a new account, use the main email // address; if they have a pending address change, use that. $to = ($pending = $user->getPendingEmail()) ? $pending : $user->getEmail(); - $this->serviceLocator->get(Mailer::class)->send( + $this->getService(Mailer::class)->send( $to, $config->Site->email, $this->translate('verification_email_subject'), @@ -2118,7 +2109,7 @@ public function changeEmailAction() // Special case: form was submitted: if ($this->formWasSubmitted(useCaptcha: $view->useCaptcha)) { // Do CSRF check - $csrf = $this->serviceLocator->get(CsrfInterface::class); + $csrf = $this->getService(CsrfInterface::class); if (!$csrf->isValid($this->getRequest()->getPost()->get('csrf'))) { throw new \VuFind\Exception\BadRequest( 'error_inconsistent_parameters' @@ -2195,7 +2186,7 @@ public function deleteLoginTokenAction() if (!$this->getAuthManager()->getIdentity()) { return $this->forceLogin(); } - $csrf = $this->serviceLocator->get(CsrfInterface::class); + $csrf = $this->getService(CsrfInterface::class); if (!$csrf->isValid($this->getRequest()->getPost()->get('csrf'))) { throw new \VuFind\Exception\BadRequest( 'error_inconsistent_parameters' @@ -2216,7 +2207,7 @@ public function deleteUserLoginTokensAction() if (!$this->getAuthManager()->getIdentity()) { return $this->forceLogin(); } - $csrf = $this->serviceLocator->get(CsrfInterface::class); + $csrf = $this->getService(CsrfInterface::class); if (!$csrf->isValid($this->getRequest()->getPost()->get('csrf'))) { throw new \VuFind\Exception\BadRequest( 'error_inconsistent_parameters' @@ -2275,7 +2266,7 @@ public function deleteAccountAction() $view = $this->createViewModel(['accountDeleted' => false]); if ($this->formWasSubmitted()) { - $csrf = $this->serviceLocator->get(CsrfInterface::class); + $csrf = $this->getService(CsrfInterface::class); if (!$csrf->isValid($this->getRequest()->getPost()->get('csrf'))) { throw new \VuFind\Exception\BadRequest( 'error_inconsistent_parameters' @@ -2284,7 +2275,7 @@ public function deleteAccountAction() // After successful token verification, clear list to shrink session: $csrf->trimTokenList(0); } - $this->serviceLocator->get(UserAccountService::class)->purgeUserData( + $this->getService(UserAccountService::class)->purgeUserData( $user, $config->Authentication->delete_comments_with_user ?? true, $config->Authentication->delete_ratings_with_user ?? true @@ -2320,7 +2311,7 @@ public function unsubscribeAction() if (!$search) { throw new \Exception('Invalid parameters.'); } - $secret = $this->serviceLocator->get(SecretCalculator::class)->getSearchUnsubscribeSecret($search); + $secret = $this->getService(SecretCalculator::class)->getSearchUnsubscribeSecret($search); if ($key !== $secret) { throw new \Exception('Invalid parameters.'); } @@ -2354,8 +2345,7 @@ protected function getPaginationHelper() */ protected function listTagsEnabled() { - $check = $this->serviceLocator - ->get(\VuFind\Config\AccountCapabilities::class); + $check = $this->getService(\VuFind\Config\AccountCapabilities::class); return $check->getListTagSetting() === 'enabled'; } diff --git a/module/VuFind/src/VuFind/Controller/OaiController.php b/module/VuFind/src/VuFind/Controller/OaiController.php index 6adef103bce..8c7d2752090 100644 --- a/module/VuFind/src/VuFind/Controller/OaiController.php +++ b/module/VuFind/src/VuFind/Controller/OaiController.php @@ -103,13 +103,13 @@ protected function handleOAI($serverClass) $this->getRequest()->getQuery()->toArray(), $this->getRequest()->getPost()->toArray() ); - $server = $this->serviceLocator->get($serverClass); + $server = $this->getService($serverClass); $server->init($config, $baseURL, $params); $server->setRecordLinkerHelper( $this->getViewRenderer()->plugin('recordLinker') ); $server->setRecordFormatter( - $this->serviceLocator->get(RecordFormatter::class) + $this->getService(RecordFormatter::class) ); $xml = $server->getResponse(); } catch (\Exception $e) { diff --git a/module/VuFind/src/VuFind/Controller/OverdriveController.php b/module/VuFind/src/VuFind/Controller/OverdriveController.php index c2ca5dfd647..751d54b8e48 100644 --- a/module/VuFind/src/VuFind/Controller/OverdriveController.php +++ b/module/VuFind/src/VuFind/Controller/OverdriveController.php @@ -112,8 +112,7 @@ public function mycontentAction() try { $this->debug("loading checkout using: $idToLoad"); - $mycheckout['record'] - = $this->serviceLocator->get(\VuFind\Record\Loader::class) + $mycheckout['record'] = $this->getService(\VuFind\Record\Loader::class) ->load($idToLoad); $checkouts[] = $mycheckout; } catch (\VuFind\Exception\RecordMissing $e) { @@ -148,7 +147,7 @@ public function mycontentAction() $myhold['hold'] = $hold; try { $myhold['record'] - = $this->serviceLocator->get(\VuFind\Record\Loader::class) + = $this->getService(\VuFind\Record\Loader::class) ->load(strtolower($hold->reserveId)); $holds[] = $myhold; } catch (\VuFind\Exception\RecordMissing $e) { @@ -241,7 +240,7 @@ public function holdAction() $this->debug("ODRC od_id=$od_id rec_id=$rec_id action=$action"); // Load the Record Driver. Should be a SolrOverdrive driver. - $driver = $this->serviceLocator->get(\VuFind\Record\Loader::class)->load( + $driver = $this->getService(\VuFind\Record\Loader::class)->load( $rec_id ); @@ -345,7 +344,7 @@ public function getConfirmCheckoutRes() $od_id = $this->params()->fromQuery('od_id'); $rec_id = $this->params()->fromQuery('rec_id'); // Load the Record Driver. Should be a SolrOverdrive driver. - $driver = $this->serviceLocator->get(\VuFind\Record\Loader::class)->load( + $driver = $this->getService(\VuFind\Record\Loader::class)->load( $rec_id ); $formats = $driver->getDigitalFormats(); @@ -473,7 +472,7 @@ public function getReturnTitleConfirmResult() $result = $this->connector->getResultObject(); $rec_id = $this->params()->fromQuery('rec_id'); // Load the SolrOverdrive driver. - $driver = $this->serviceLocator->get(\VuFind\Record\Loader::class)->load( + $driver = $this->getService(\VuFind\Record\Loader::class)->load( $rec_id ); $formats = $driver->getDigitalFormats(); diff --git a/module/VuFind/src/VuFind/Controller/PrimoController.php b/module/VuFind/src/VuFind/Controller/PrimoController.php index 9ea7484f140..fec470dba72 100644 --- a/module/VuFind/src/VuFind/Controller/PrimoController.php +++ b/module/VuFind/src/VuFind/Controller/PrimoController.php @@ -64,8 +64,7 @@ public function __construct(ServiceLocatorInterface $sm) */ protected function resultScrollerActive() { - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class) - ->get('Primo'); + $config = $this->getService(\VuFind\Config\PluginManager::class)->get('Primo'); return $config->Record->next_prev_navigation ?? false; } diff --git a/module/VuFind/src/VuFind/Controller/PrimorecordController.php b/module/VuFind/src/VuFind/Controller/PrimorecordController.php index 1e9ae7483d3..f5ccfb13636 100644 --- a/module/VuFind/src/VuFind/Controller/PrimorecordController.php +++ b/module/VuFind/src/VuFind/Controller/PrimorecordController.php @@ -65,8 +65,7 @@ public function __construct(ServiceLocatorInterface $sm) */ protected function resultScrollerActive() { - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class) - ->get('Primo'); + $config = $this->getService(\VuFind\Config\PluginManager::class)->get('Primo'); return $config->Record->next_prev_navigation ?? false; } } diff --git a/module/VuFind/src/VuFind/Controller/RecordController.php b/module/VuFind/src/VuFind/Controller/RecordController.php index bd03493dd16..8768240c272 100644 --- a/module/VuFind/src/VuFind/Controller/RecordController.php +++ b/module/VuFind/src/VuFind/Controller/RecordController.php @@ -69,8 +69,7 @@ public function __construct(ServiceLocatorInterface $sm, Config $config) */ protected function resultScrollerActive() { - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class) - ->get('config'); + $config = $this->getService(\VuFind\Config\PluginManager::class)->get('config'); return $config->Record->next_prev_navigation ?? false; } } diff --git a/module/VuFind/src/VuFind/Controller/Search2Controller.php b/module/VuFind/src/VuFind/Controller/Search2Controller.php index 34831add233..34ce0a690ee 100644 --- a/module/VuFind/src/VuFind/Controller/Search2Controller.php +++ b/module/VuFind/src/VuFind/Controller/Search2Controller.php @@ -60,8 +60,7 @@ public function __construct(ServiceLocatorInterface $sm) */ protected function resultScrollerActive() { - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class) - ->get('Search2'); + $config = $this->getService(\VuFind\Config\PluginManager::class)->get('Search2'); return $config->Record->next_prev_navigation ?? false; } } diff --git a/module/VuFind/src/VuFind/Controller/Search2recordController.php b/module/VuFind/src/VuFind/Controller/Search2recordController.php index a22906703b0..83307e6e016 100644 --- a/module/VuFind/src/VuFind/Controller/Search2recordController.php +++ b/module/VuFind/src/VuFind/Controller/Search2recordController.php @@ -61,8 +61,7 @@ public function __construct(ServiceLocatorInterface $sm) */ protected function resultScrollerActive() { - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class) - ->get('Search2'); + $config = $this->getService(\VuFind\Config\PluginManager::class)->get('Search2'); return $config->Record->next_prev_navigation ?? false; } } diff --git a/module/VuFind/src/VuFind/Controller/SearchController.php b/module/VuFind/src/VuFind/Controller/SearchController.php index 6c1999f26c6..4033b5d0de4 100644 --- a/module/VuFind/src/VuFind/Controller/SearchController.php +++ b/module/VuFind/src/VuFind/Controller/SearchController.php @@ -81,7 +81,7 @@ public function editmemoryAction() // Retrieve and manipulate the parameters: $searchHelper = $this->getViewRenderer()->plugin('searchMemory'); $params = $searchHelper->getLastSearchParams($searchClassId); - $factory = $this->serviceLocator->get(UrlQueryHelperFactory::class); + $factory = $this->getService(UrlQueryHelperFactory::class); $initialParams = $factory->fromParams($params); if ($removeAllFilters) { @@ -123,7 +123,7 @@ public function emailAction() { // If a URL was explicitly passed in, use that; otherwise, try to // find the HTTP referrer. - $mailer = $this->serviceLocator->get(\VuFind\Mailer\Mailer::class); + $mailer = $this->getService(\VuFind\Mailer\Mailer::class); $view = $this->createEmailViewModel(null, $mailer->getDefaultLinkSubject()); $mailer->setMaxRecipients($view->maxRecipients); // Set up Captcha @@ -196,8 +196,7 @@ public function historyAction() } $userId = $user?->getId(); - $searchHistoryHelper = $this->serviceLocator - ->get(\VuFind\Search\History::class); + $searchHistoryHelper = $this->getService(\VuFind\Search\History::class); if ($this->params()->fromQuery('purge')) { $searchHistoryHelper->purgeSearchHistory($userId); @@ -208,8 +207,7 @@ public function historyAction() $viewData = $searchHistoryHelper->getSearchHistory($userId); // Eliminate schedule settings if scheduled searches are disabled; add // user email data if scheduled searches are enabled. - $scheduleOptions = $this->serviceLocator - ->get(\VuFind\Search\History::class) + $scheduleOptions = $this->getService(\VuFind\Search\History::class) ->getScheduleOptions(); if (empty($scheduleOptions)) { unset($viewData['schedule']); @@ -240,8 +238,7 @@ public function newitemAction() ] ); if ($this->newItems()->includeFacets()) { - $view->options = $this->serviceLocator - ->get(\VuFind\Search\Options\PluginManager::class) + $view->options = $this->getService(\VuFind\Search\Options\PluginManager::class) ->get($this->searchClassId); $this->addFacetDetailsToView($view, 'NewItems'); } @@ -373,7 +370,7 @@ public function reservessearchAction() + $this->getRequest()->getPost()->toArray() ); $view = $this->createViewModel(); - $runner = $this->serviceLocator->get(\VuFind\Search\SearchRunner::class); + $runner = $this->getService(\VuFind\Search\SearchRunner::class); $view->results = $runner->run( $request, 'SolrReserves', @@ -512,8 +509,7 @@ public function suggestAction() // Get suggestions and make sure they are an array (we don't want to JSON // encode them into an object): - $suggester = $this->serviceLocator - ->get(\VuFind\Autocomplete\Suggester::class); + $suggester = $this->getService(\VuFind\Autocomplete\Suggester::class); $suggestions = $suggester->getSuggestions($query, 'type', 'lookfor'); // Send the JSON response: @@ -533,8 +529,7 @@ public function suggestAction() */ protected function resultScrollerActive() { - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class) - ->get('config'); + $config = $this->getService(\VuFind\Config\PluginManager::class)->get('config'); return $config->Record->next_prev_navigation ?? false; } } diff --git a/module/VuFind/src/VuFind/Controller/ShibbolethLogoutNotificationController.php b/module/VuFind/src/VuFind/Controller/ShibbolethLogoutNotificationController.php index 4a9541d9de2..da51e89bf14 100644 --- a/module/VuFind/src/VuFind/Controller/ShibbolethLogoutNotificationController.php +++ b/module/VuFind/src/VuFind/Controller/ShibbolethLogoutNotificationController.php @@ -119,7 +119,7 @@ public function logoutNotification($sessionId) $rows = $this->getDbService(ExternalSessionServiceInterface::class) ->getAllByExternalSessionId(trim($sessionId)); if ($rows) { - $sessionManager = $this->serviceLocator->get(\Laminas\Session\SessionManager::class); + $sessionManager = $this->getService(\Laminas\Session\SessionManager::class); $handler = $sessionManager->getSaveHandler(); foreach ($rows as $row) { $handler->destroy($row->getSessionId()); diff --git a/module/VuFind/src/VuFind/Controller/ShortlinkController.php b/module/VuFind/src/VuFind/Controller/ShortlinkController.php index ec24882b3f0..da0bc44b74a 100644 --- a/module/VuFind/src/VuFind/Controller/ShortlinkController.php +++ b/module/VuFind/src/VuFind/Controller/ShortlinkController.php @@ -115,7 +115,7 @@ protected function redirectViaHttp($url) public function redirectAction() { if ($id = $this->params('id')) { - $resolver = $this->serviceLocator->get(UrlShortenerInterface::class); + $resolver = $this->getService(UrlShortenerInterface::class); if ($url = $resolver->resolve($id)) { $threshRegEx = '"^threshold:(\d+)$"i'; if (preg_match($threshRegEx, $this->redirectMethod, $hits)) { diff --git a/module/VuFind/src/VuFind/Controller/StorageRetrievalRequestsTrait.php b/module/VuFind/src/VuFind/Controller/StorageRetrievalRequestsTrait.php index 5cc198f28b4..636fe8f8ad6 100644 --- a/module/VuFind/src/VuFind/Controller/StorageRetrievalRequestsTrait.php +++ b/module/VuFind/src/VuFind/Controller/StorageRetrievalRequestsTrait.php @@ -159,8 +159,7 @@ public function storageRetrievalRequestAction() // Find and format the default required date: $defaultRequiredDate = $this->storageRetrievalRequests() ->getDefaultRequiredDate($checkRequests); - $defaultRequiredDate - = $this->serviceLocator->get(\VuFind\Date\Converter::class) + $defaultRequiredDate = $this->getService(\VuFind\Date\Converter::class) ->convertToDisplayDate('U', $defaultRequiredDate); try { $defaultPickup diff --git a/module/VuFind/src/VuFind/Controller/SummonController.php b/module/VuFind/src/VuFind/Controller/SummonController.php index ed1b082fad4..1284b97d507 100644 --- a/module/VuFind/src/VuFind/Controller/SummonController.php +++ b/module/VuFind/src/VuFind/Controller/SummonController.php @@ -61,8 +61,7 @@ public function __construct(ServiceLocatorInterface $sm) */ protected function resultScrollerActive() { - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class) - ->get('Summon'); + $config = $this->getService(\VuFind\Config\PluginManager::class)->get('Summon'); return $config->Record->next_prev_navigation ?? false; } @@ -108,8 +107,8 @@ public function advancedAction() $view = parent::advancedAction(); // Set up facet information: - $facets = $this->serviceLocator - ->get(\VuFind\Search\FacetCache\PluginManager::class)->get('Summon') + $facets = $this->getService(\VuFind\Search\FacetCache\PluginManager::class) + ->get('Summon') ->getList('Advanced'); $view->facetList = $this->processAdvancedFacets($facets, $view->saved); $specialFacets = $this->parseSpecialFacetsSetting( diff --git a/module/VuFind/src/VuFind/Controller/SummonrecordController.php b/module/VuFind/src/VuFind/Controller/SummonrecordController.php index 9645868eae5..9dff4afd095 100644 --- a/module/VuFind/src/VuFind/Controller/SummonrecordController.php +++ b/module/VuFind/src/VuFind/Controller/SummonrecordController.php @@ -65,8 +65,7 @@ public function __construct(ServiceLocatorInterface $sm) */ protected function resultScrollerActive() { - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class) - ->get('Summon'); + $config = $this->getService(\VuFind\Config\PluginManager::class)->get('Summon'); return $config->Record->next_prev_navigation ?? false; } diff --git a/module/VuFind/src/VuFind/Controller/UpgradeController.php b/module/VuFind/src/VuFind/Controller/UpgradeController.php index b7773d0714b..0ba2df194b8 100644 --- a/module/VuFind/src/VuFind/Controller/UpgradeController.php +++ b/module/VuFind/src/VuFind/Controller/UpgradeController.php @@ -273,7 +273,7 @@ protected function getRootDbAdapter() // subsequent calls. static $adapter = false; if (!$adapter) { - $factory = $this->serviceLocator->get(AdapterFactory::class); + $factory = $this->getService(AdapterFactory::class); $adapter = $factory->getAdapter( $this->session->dbRootUser, $this->session->dbRootPass @@ -346,7 +346,7 @@ protected function fixInvalidUserIdsInSearchTable(): void */ protected function fixSearchChecksumsInDatabase() { - $manager = $this->serviceLocator->get(ResultsManager::class); + $manager = $this->getService(ResultsManager::class); $searchService = $this->getDbService(SearchServiceInterface::class); $searchRows = $searchService->getSavedSearchesWithMissingChecksums(); if (count($searchRows) > 0) { @@ -561,8 +561,7 @@ public function fixdatabaseAction() // If this is a MySQL connection, we can do an automatic upgrade; // if VuFind is using a different database, we have to prompt the // user to check the migrations directory and upgrade manually. - $adapter = $this->serviceLocator - ->get(Adapter::class); + $adapter = $this->getService(Adapter::class); $platform = $adapter->getDriver()->getDatabasePlatformName(); if (strtolower($platform) == 'mysql') { $upgradeResult = $this->upgradeMySQL($adapter); @@ -589,7 +588,7 @@ public function fixdatabaseAction() $this->getRequest()->getQuery()->set('anonymousCnt', $anonymousTags); return $this->redirect()->toRoute('upgrade-fixanonymoustags'); } - $dupeTags = $this->serviceLocator->get(TagsService::class)->getDuplicateTags(); + $dupeTags = $this->getService(TagsService::class)->getDuplicateTags(); if (count($dupeTags) > 0 && !isset($this->cookie->skipDupeTags)) { return $this->redirect()->toRoute('upgrade-fixduplicatetags'); } @@ -683,8 +682,7 @@ public function getdbcredentialsAction() // Test the connection: try { // Query a table known to exist - $factory = $this->serviceLocator - ->get(AdapterFactory::class); + $factory = $this->getService(AdapterFactory::class); $db = $factory->getAdapter($dbrootuser, $pass); $db->query('SELECT * FROM user;'); $this->session->dbRootUser = $dbrootuser; @@ -757,7 +755,7 @@ public function fixduplicatetagsAction() // Handle submit action: if ($this->formWasSubmitted()) { - $this->serviceLocator->get(TagsService::class)->fixDuplicateTags(); + $this->getService(TagsService::class)->fixDuplicateTags(); return $this->forwardTo('Upgrade', 'FixDatabase'); } @@ -793,7 +791,7 @@ public function fixmetadataAction() // Process submit button: if ($this->formWasSubmitted()) { - $resourcePopulator = $this->serviceLocator->get(ResourcePopulator::class); + $resourcePopulator = $this->getService(ResourcePopulator::class); foreach ($problems as $problem) { $recordId = $problem->getRecordId(); $source = $problem->getSource(); @@ -960,7 +958,7 @@ public function homeAction() { // If the cache is messed up, nothing is going to work right -- check that // first: - $cache = $this->serviceLocator->get(CacheManager::class); + $cache = $this->getService(CacheManager::class); if ($cache->hasDirectoryCreationError()) { return $this->redirect()->toRoute('install-fixcache'); } diff --git a/module/VuFind/src/VuFind/Controller/WorldcatController.php b/module/VuFind/src/VuFind/Controller/WorldcatController.php index c56213a1a6a..8a2725a4f23 100644 --- a/module/VuFind/src/VuFind/Controller/WorldcatController.php +++ b/module/VuFind/src/VuFind/Controller/WorldcatController.php @@ -60,8 +60,7 @@ public function __construct(ServiceLocatorInterface $sm) */ protected function resultScrollerActive() { - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class) - ->get('WorldCat'); + $config = $this->getService(\VuFind\Config\PluginManager::class)->get('WorldCat'); return $config->Record->next_prev_navigation ?? false; } diff --git a/module/VuFind/src/VuFind/Controller/WorldcatrecordController.php b/module/VuFind/src/VuFind/Controller/WorldcatrecordController.php index 5e95fd340dc..8ec083c1b4e 100644 --- a/module/VuFind/src/VuFind/Controller/WorldcatrecordController.php +++ b/module/VuFind/src/VuFind/Controller/WorldcatrecordController.php @@ -63,8 +63,7 @@ public function __construct(ServiceLocatorInterface $sm) */ protected function resultScrollerActive() { - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class) - ->get('WorldCat'); + $config = $this->getService(\VuFind\Config\PluginManager::class)->get('WorldCat'); return $config->Record->next_prev_navigation ?? false; } } diff --git a/module/VuFind/src/VuFind/RateLimiter/RateLimiterManagerFactory.php b/module/VuFind/src/VuFind/RateLimiter/RateLimiterManagerFactory.php index 7e7a736324b..35cb97561ea 100644 --- a/module/VuFind/src/VuFind/RateLimiter/RateLimiterManagerFactory.php +++ b/module/VuFind/src/VuFind/RateLimiter/RateLimiterManagerFactory.php @@ -43,6 +43,7 @@ use Symfony\Component\RateLimiter\Storage\CacheStorage; use Symfony\Component\RateLimiter\Storage\StorageInterface; use VuFind\RateLimiter\Storage\CredisStorage; +use VuFind\Service\GetServiceTrait; /** * Rate limiter manager factory. @@ -55,12 +56,7 @@ */ class RateLimiterManagerFactory implements FactoryInterface { - /** - * Service locator - * - * @var ContainerInterface - */ - protected $serviceLocator; + use GetServiceTrait; /** * Create an object @@ -151,7 +147,7 @@ protected function createCache(array $config): StorageInterface if ('vufind' === $adapterLc) { // Use cache manager for "VuFind" cache (only for testing purposes): - $cacheManager = $this->serviceLocator->get(\VuFind\Cache\Manager::class); + $cacheManager = $this->getService(\VuFind\Cache\Manager::class); $laminasCache = $cacheManager->getCache('object', $storageConfig['options']['namespace']); // Fake the capabilities to include static TTL support: $eventManager = $laminasCache->getEventManager(); @@ -178,8 +174,7 @@ function ($event) use ($laminasCache) { 'adapter' => $adapter, 'options' => $storageConfig['options'], ]; - $laminasCache = $this->serviceLocator - ->get(\Laminas\Cache\Service\StorageAdapterFactory::class) + $laminasCache = $this->getService(\Laminas\Cache\Service\StorageAdapterFactory::class) ->createFromArrayConfiguration($settings); } diff --git a/module/VuFind/src/VuFind/Search/Factory/AbstractBackendFactory.php b/module/VuFind/src/VuFind/Search/Factory/AbstractBackendFactory.php index 3d473124589..cb5b9c72995 100644 --- a/module/VuFind/src/VuFind/Search/Factory/AbstractBackendFactory.php +++ b/module/VuFind/src/VuFind/Search/Factory/AbstractBackendFactory.php @@ -33,6 +33,7 @@ use Laminas\Config\Config; use Laminas\ServiceManager\Factory\FactoryInterface; use Psr\Container\ContainerInterface; +use VuFind\Service\GetServiceTrait; /** * Abstract factory for backends. @@ -45,12 +46,7 @@ */ abstract class AbstractBackendFactory implements FactoryInterface { - /** - * Service container. - * - * @var ContainerInterface - */ - protected $serviceLocator; + use GetServiceTrait; /** * Constructor @@ -86,8 +82,7 @@ protected function createHttpClient( array $options = [], string $url = null ): \Laminas\Http\Client { - $client = $this->serviceLocator->get(\VuFindHttp\HttpService::class) - ->createClient($url); + $client = $this->getService(\VuFindHttp\HttpService::class)->createClient($url); if (null !== $timeout) { $options['timeout'] = $timeout; } @@ -119,8 +114,7 @@ protected function createConnectorCache(Config $searchConfig): ?StorageInterface 'adapter' => $cacheConfig['adapter'], 'options' => $options, ]; - return $this->serviceLocator - ->get(\Laminas\Cache\Service\StorageAdapterFactory::class) + return $this->getService(\Laminas\Cache\Service\StorageAdapterFactory::class) ->createFromArrayConfiguration($settings); } } diff --git a/module/VuFind/src/VuFind/Search/Factory/AbstractSolrBackendFactory.php b/module/VuFind/src/VuFind/Search/Factory/AbstractSolrBackendFactory.php index 5505a2be410..60712f704de 100644 --- a/module/VuFind/src/VuFind/Search/Factory/AbstractSolrBackendFactory.php +++ b/module/VuFind/src/VuFind/Search/Factory/AbstractSolrBackendFactory.php @@ -200,10 +200,9 @@ public function __construct() public function __invoke(ContainerInterface $sm, $name, array $options = null) { $this->setup($sm); - $this->config = $this->serviceLocator - ->get(\VuFind\Config\PluginManager::class); + $this->config = $this->getService(\VuFind\Config\PluginManager::class); if ($this->serviceLocator->has(\VuFind\Log\Logger::class)) { - $this->logger = $this->serviceLocator->get(\VuFind\Log\Logger::class); + $this->logger = $this->getService(\VuFind\Log\Logger::class); } $connector = $this->createConnector(); $backend = $this->createBackend($connector); @@ -308,7 +307,7 @@ protected function createBackend(Connector $connector) */ protected function createListeners(Backend $backend) { - $events = $this->serviceLocator->get('SharedEventManager'); + $events = $this->getService('SharedEventManager'); // Load configurations: $config = $this->config->get($this->mainConfig); @@ -616,8 +615,7 @@ protected function getCreateRecordCallback(): ?callable */ protected function loadSpecs() { - return $this->serviceLocator->get(\VuFind\Config\SearchSpecsReader::class) - ->get($this->searchYaml); + return $this->getService(\VuFind\Config\SearchSpecsReader::class)->get($this->searchYaml); } /** @@ -713,8 +711,7 @@ protected function getInjectConditionalFilterListener(BackendInterface $backend, $search->ConditionalHiddenFilters->toArray() ); $listener->setAuthorizationService( - $this->serviceLocator - ->get(\LmcRbacMvc\Service\AuthorizationService::class) + $this->getService(\LmcRbacMvc\Service\AuthorizationService::class) ); return $listener; } diff --git a/module/VuFind/src/VuFind/Search/Factory/BrowZineBackendFactory.php b/module/VuFind/src/VuFind/Search/Factory/BrowZineBackendFactory.php index a9886dd735c..683d8d7b241 100644 --- a/module/VuFind/src/VuFind/Search/Factory/BrowZineBackendFactory.php +++ b/module/VuFind/src/VuFind/Search/Factory/BrowZineBackendFactory.php @@ -74,11 +74,10 @@ class BrowZineBackendFactory extends AbstractBackendFactory public function __invoke(ContainerInterface $sm, $name, array $options = null) { $this->setup($sm); - $configReader = $this->serviceLocator - ->get(\VuFind\Config\PluginManager::class); + $configReader = $this->getService(\VuFind\Config\PluginManager::class); $this->browzineConfig = $configReader->get('BrowZine'); if ($this->serviceLocator->has(\VuFind\Log\Logger::class)) { - $this->logger = $this->serviceLocator->get(\VuFind\Log\Logger::class); + $this->logger = $this->getService(\VuFind\Log\Logger::class); } $connector = $this->createConnector(); @@ -145,8 +144,7 @@ protected function createQueryBuilder() */ protected function createRecordCollectionFactory() { - $manager = $this->serviceLocator - ->get(\VuFind\RecordDriver\PluginManager::class); + $manager = $this->getService(\VuFind\RecordDriver\PluginManager::class); $callback = function ($data) use ($manager) { $driver = $manager->get('BrowZine'); $driver->setRawData($data); diff --git a/module/VuFind/src/VuFind/Search/Factory/EITBackendFactory.php b/module/VuFind/src/VuFind/Search/Factory/EITBackendFactory.php index 8ad35d80ba2..08c8bc8ae7c 100644 --- a/module/VuFind/src/VuFind/Search/Factory/EITBackendFactory.php +++ b/module/VuFind/src/VuFind/Search/Factory/EITBackendFactory.php @@ -76,11 +76,9 @@ class EITBackendFactory extends AbstractBackendFactory public function __invoke(ContainerInterface $sm, $name, array $options = null) { $this->setup($sm); - $this->config = $this->serviceLocator - ->get(\VuFind\Config\PluginManager::class) - ->get('EIT'); + $this->config = $this->getService(\VuFind\Config\PluginManager::class)->get('EIT'); if ($this->serviceLocator->has(\VuFind\Log\Logger::class)) { - $this->logger = $this->serviceLocator->get(\VuFind\Log\Logger::class); + $this->logger = $this->getService(\VuFind\Log\Logger::class); } $connector = $this->createConnector(); $backend = $this->createBackend($connector); @@ -142,8 +140,7 @@ protected function createQueryBuilder() */ protected function createRecordCollectionFactory() { - $manager = $this->serviceLocator - ->get(\VuFind\RecordDriver\PluginManager::class); + $manager = $this->getService(\VuFind\RecordDriver\PluginManager::class); $callback = function ($data) use ($manager) { $driver = $manager->get('EIT'); $driver->setRawData($data); diff --git a/module/VuFind/src/VuFind/Search/Factory/EdsBackendFactory.php b/module/VuFind/src/VuFind/Search/Factory/EdsBackendFactory.php index 9e0f615d38c..a6f84f4e8c3 100644 --- a/module/VuFind/src/VuFind/Search/Factory/EdsBackendFactory.php +++ b/module/VuFind/src/VuFind/Search/Factory/EdsBackendFactory.php @@ -101,11 +101,10 @@ protected function getServiceName() public function __invoke(ContainerInterface $sm, $name, array $options = null) { $this->setup($sm); - $this->edsConfig = $this->serviceLocator - ->get(\VuFind\Config\PluginManager::class) + $this->edsConfig = $this->getService(\VuFind\Config\PluginManager::class) ->get($this->getServiceName()); if ($this->serviceLocator->has(\VuFind\Log\Logger::class)) { - $this->logger = $this->serviceLocator->get(\VuFind\Log\Logger::class); + $this->logger = $this->getService(\VuFind\Log\Logger::class); } $connector = $this->createConnector(); $backend = $this->createBackend($connector); @@ -122,24 +121,23 @@ public function __invoke(ContainerInterface $sm, $name, array $options = null) */ protected function createBackend(Connector $connector) { - $auth = $this->serviceLocator - ->get(\LmcRbacMvc\Service\AuthorizationService::class); + $auth = $this->getService(\LmcRbacMvc\Service\AuthorizationService::class); $isGuest = !$auth->isGranted('access.EDSExtendedResults'); $session = new \Laminas\Session\Container( 'EBSCO', - $this->serviceLocator->get(\Laminas\Session\SessionManager::class) + $this->getService(\Laminas\Session\SessionManager::class) ); $backend = new Backend( $connector, $this->createRecordCollectionFactory(), - $this->serviceLocator->get(\VuFind\Cache\Manager::class) + $this->getService(\VuFind\Cache\Manager::class) ->getCache('object'), $session, $this->edsConfig, $isGuest ); $backend->setAuthManager( - $this->serviceLocator->get(\VuFind\Auth\Manager::class) + $this->getService(\VuFind\Auth\Manager::class) ); $backend->setLogger($this->logger); $backend->setQueryBuilder($this->createQueryBuilder()); @@ -213,8 +211,7 @@ protected function createQueryBuilder() */ protected function createRecordCollectionFactory() { - $manager = $this->serviceLocator - ->get(\VuFind\RecordDriver\PluginManager::class); + $manager = $this->getService(\VuFind\RecordDriver\PluginManager::class); $callback = function ($data) use ($manager) { $driver = $manager->get($this->getServiceName()); $driver->setRawData($data); @@ -232,7 +229,7 @@ protected function createRecordCollectionFactory() */ protected function createListeners(Backend $backend) { - $events = $this->serviceLocator->get('SharedEventManager'); + $events = $this->getService('SharedEventManager'); // Attach hide facet value listener: $hfvListener = $this->getHideFacetValueListener($backend, $this->edsConfig); diff --git a/module/VuFind/src/VuFind/Search/Factory/LibGuidesBackendFactory.php b/module/VuFind/src/VuFind/Search/Factory/LibGuidesBackendFactory.php index 8d1d6d3c5aa..a60fda01d5e 100644 --- a/module/VuFind/src/VuFind/Search/Factory/LibGuidesBackendFactory.php +++ b/module/VuFind/src/VuFind/Search/Factory/LibGuidesBackendFactory.php @@ -84,11 +84,10 @@ protected function getServiceName() public function __invoke(ContainerInterface $sm, $name, array $options = null) { $this->setup($sm); - $configReader = $this->serviceLocator - ->get(\VuFind\Config\PluginManager::class); + $configReader = $this->getService(\VuFind\Config\PluginManager::class); $this->libGuidesConfig = $configReader->get($this->getServiceName()); if ($this->serviceLocator->has(\VuFind\Log\Logger::class)) { - $this->logger = $this->serviceLocator->get(\VuFind\Log\Logger::class); + $this->logger = $this->getService(\VuFind\Log\Logger::class); } $connector = $this->createConnector(); $backend = $this->createBackend($connector); @@ -164,8 +163,7 @@ protected function createQueryBuilder() */ protected function createRecordCollectionFactory() { - $manager = $this->serviceLocator - ->get(\VuFind\RecordDriver\PluginManager::class); + $manager = $this->getService(\VuFind\RecordDriver\PluginManager::class); $callback = function ($data) use ($manager) { $driver = $manager->get($this->getServiceName()); $driver->setRawData($data); diff --git a/module/VuFind/src/VuFind/Search/Factory/Pazpar2BackendFactory.php b/module/VuFind/src/VuFind/Search/Factory/Pazpar2BackendFactory.php index 63f6e1abe37..52f3cf368a6 100644 --- a/module/VuFind/src/VuFind/Search/Factory/Pazpar2BackendFactory.php +++ b/module/VuFind/src/VuFind/Search/Factory/Pazpar2BackendFactory.php @@ -74,11 +74,9 @@ class Pazpar2BackendFactory extends AbstractBackendFactory public function __invoke(ContainerInterface $sm, $name, array $options = null) { $this->setup($sm); - $this->config = $this->serviceLocator - ->get(\VuFind\Config\PluginManager::class) - ->get('Pazpar2'); + $this->config = $this->getService(\VuFind\Config\PluginManager::class)->get('Pazpar2'); if ($this->serviceLocator->has(\VuFind\Log\Logger::class)) { - $this->logger = $this->serviceLocator->get(\VuFind\Log\Logger::class); + $this->logger = $this->getService(\VuFind\Log\Logger::class); } $connector = $this->createConnector(); $backend = $this->createBackend($connector); @@ -140,8 +138,7 @@ protected function createQueryBuilder() */ protected function createRecordCollectionFactory() { - $manager = $this->serviceLocator - ->get(\VuFind\RecordDriver\PluginManager::class); + $manager = $this->getService(\VuFind\RecordDriver\PluginManager::class); $callback = function ($data) use ($manager) { $driver = $manager->get('Pazpar2'); $driver->setRawData($data); diff --git a/module/VuFind/src/VuFind/Search/Factory/PrimoBackendFactory.php b/module/VuFind/src/VuFind/Search/Factory/PrimoBackendFactory.php index a14a36211ca..415c9ab844a 100644 --- a/module/VuFind/src/VuFind/Search/Factory/PrimoBackendFactory.php +++ b/module/VuFind/src/VuFind/Search/Factory/PrimoBackendFactory.php @@ -102,11 +102,10 @@ class PrimoBackendFactory extends AbstractBackendFactory public function __invoke(ContainerInterface $sm, $name, array $options = null) { $this->setup($sm); - $configReader = $this->serviceLocator - ->get(\VuFind\Config\PluginManager::class); + $configReader = $this->getService(\VuFind\Config\PluginManager::class); $this->primoConfig = $configReader->get('Primo'); if ($this->serviceLocator->has(\VuFind\Log\Logger::class)) { - $this->logger = $this->serviceLocator->get(\VuFind\Log\Logger::class); + $this->logger = $this->getService(\VuFind\Log\Logger::class); } if (($this->primoConfig->General->api ?? 'legacy') === 'rest') { @@ -148,7 +147,7 @@ protected function createBackend(ConnectorInterface $connector) */ protected function createListeners(Backend $backend) { - $events = $this->serviceLocator->get('SharedEventManager'); + $events = $this->getService('SharedEventManager'); $this->getInjectOnCampusListener()->attach($events); @@ -211,7 +210,7 @@ protected function createRestConnector() $session = new \Laminas\Session\Container( 'Primo', - $this->serviceLocator->get(\Laminas\Session\SessionManager::class) + $this->getService(\Laminas\Session\SessionManager::class) ); // Create connector: @@ -254,8 +253,7 @@ protected function createQueryBuilder() */ protected function createRecordCollectionFactory() { - $manager = $this->serviceLocator - ->get(\VuFind\RecordDriver\PluginManager::class); + $manager = $this->getService(\VuFind\RecordDriver\PluginManager::class); $callback = function ($data) use ($manager) { $driver = $manager->get('Primo'); $driver->setRawData($data); @@ -287,7 +285,7 @@ protected function getPermissionHandler(): ?PrimoPermissionHandler $this->primoConfig->Institutions ); $permHandler->setAuthorizationService( - $this->serviceLocator->get(AuthorizationService::class) + $this->getService(AuthorizationService::class) ); return $permHandler; } diff --git a/module/VuFind/src/VuFind/Search/Factory/Search2BackendFactory.php b/module/VuFind/src/VuFind/Search/Factory/Search2BackendFactory.php index b1593208b6f..b6000321cb4 100644 --- a/module/VuFind/src/VuFind/Search/Factory/Search2BackendFactory.php +++ b/module/VuFind/src/VuFind/Search/Factory/Search2BackendFactory.php @@ -59,8 +59,7 @@ public function __construct() */ protected function getCreateRecordCallback(): ?callable { - $manager = $this->serviceLocator - ->get(\VuFind\RecordDriver\PluginManager::class); + $manager = $this->getService(\VuFind\RecordDriver\PluginManager::class); return [$manager, 'getSearch2Record']; } } diff --git a/module/VuFind/src/VuFind/Search/Factory/SolrAuthBackendFactory.php b/module/VuFind/src/VuFind/Search/Factory/SolrAuthBackendFactory.php index 1e569043a6a..8c7ebf80b31 100644 --- a/module/VuFind/src/VuFind/Search/Factory/SolrAuthBackendFactory.php +++ b/module/VuFind/src/VuFind/Search/Factory/SolrAuthBackendFactory.php @@ -63,8 +63,7 @@ public function __construct() */ protected function getCreateRecordCallback(): ?callable { - $manager = $this->serviceLocator - ->get(\VuFind\RecordDriver\PluginManager::class); + $manager = $this->getService(\VuFind\RecordDriver\PluginManager::class); return [$manager, 'getSolrAuthRecord']; } } diff --git a/module/VuFind/src/VuFind/Search/Factory/SolrDefaultBackendFactory.php b/module/VuFind/src/VuFind/Search/Factory/SolrDefaultBackendFactory.php index e4c98cea3fd..4a4016510df 100644 --- a/module/VuFind/src/VuFind/Search/Factory/SolrDefaultBackendFactory.php +++ b/module/VuFind/src/VuFind/Search/Factory/SolrDefaultBackendFactory.php @@ -62,8 +62,7 @@ public function __construct() */ protected function getCreateRecordCallback(): ?callable { - $manager = $this->serviceLocator - ->get(\VuFind\RecordDriver\PluginManager::class); + $manager = $this->getService(\VuFind\RecordDriver\PluginManager::class); return [$manager, 'getSolrRecord']; } } diff --git a/module/VuFind/src/VuFind/Search/Factory/SolrReservesBackendFactory.php b/module/VuFind/src/VuFind/Search/Factory/SolrReservesBackendFactory.php index fd6d47ffd21..cf53a052877 100644 --- a/module/VuFind/src/VuFind/Search/Factory/SolrReservesBackendFactory.php +++ b/module/VuFind/src/VuFind/Search/Factory/SolrReservesBackendFactory.php @@ -61,8 +61,7 @@ public function __construct() */ protected function getCreateRecordCallback(): ?callable { - $manager = $this->serviceLocator - ->get(\VuFind\RecordDriver\PluginManager::class); + $manager = $this->getService(\VuFind\RecordDriver\PluginManager::class); return function ($data) use ($manager) { $driver = $manager->get('SolrReserves'); $driver->setRawData($data); diff --git a/module/VuFind/src/VuFind/Search/Factory/SolrWebBackendFactory.php b/module/VuFind/src/VuFind/Search/Factory/SolrWebBackendFactory.php index c1932a1fc27..68a4abd6eff 100644 --- a/module/VuFind/src/VuFind/Search/Factory/SolrWebBackendFactory.php +++ b/module/VuFind/src/VuFind/Search/Factory/SolrWebBackendFactory.php @@ -61,8 +61,7 @@ public function __construct() */ protected function getCreateRecordCallback(): ?callable { - $manager = $this->serviceLocator - ->get(\VuFind\RecordDriver\PluginManager::class); + $manager = $this->getService(\VuFind\RecordDriver\PluginManager::class); return function ($data) use ($manager) { $driver = $manager->get('SolrWeb'); $driver->setRawData($data); diff --git a/module/VuFind/src/VuFind/Search/Factory/SummonBackendFactory.php b/module/VuFind/src/VuFind/Search/Factory/SummonBackendFactory.php index 17d2bd5f766..9fb4a4b0855 100644 --- a/module/VuFind/src/VuFind/Search/Factory/SummonBackendFactory.php +++ b/module/VuFind/src/VuFind/Search/Factory/SummonBackendFactory.php @@ -82,12 +82,11 @@ class SummonBackendFactory extends AbstractBackendFactory public function __invoke(ContainerInterface $sm, $name, array $options = null) { $this->setup($sm); - $configReader = $this->serviceLocator - ->get(\VuFind\Config\PluginManager::class); + $configReader = $this->getService(\VuFind\Config\PluginManager::class); $this->config = $configReader->get('config'); $this->summonConfig = $configReader->get('Summon'); if ($this->serviceLocator->has(\VuFind\Log\Logger::class)) { - $this->logger = $this->serviceLocator->get(\VuFind\Log\Logger::class); + $this->logger = $this->getService(\VuFind\Log\Logger::class); } $connector = $this->createConnector(); $backend = $this->createBackend($connector); @@ -139,8 +138,7 @@ protected function createConnector() */ protected function isAuthed() { - return $this->serviceLocator - ->get(\LmcRbacMvc\Service\AuthorizationService::class) + return $this->getService(\LmcRbacMvc\Service\AuthorizationService::class) ->isGranted('access.SummonExtendedResults'); } @@ -166,8 +164,7 @@ protected function createQueryBuilder() */ protected function createRecordCollectionFactory() { - $manager = $this->serviceLocator - ->get(\VuFind\RecordDriver\PluginManager::class); + $manager = $this->getService(\VuFind\RecordDriver\PluginManager::class); $stripSnippets = !($this->summonConfig->General->snippets ?? false); $callback = function ($data) use ($manager, $stripSnippets) { $driver = $manager->get('Summon'); diff --git a/module/VuFind/src/VuFind/Search/Factory/WorldCatBackendFactory.php b/module/VuFind/src/VuFind/Search/Factory/WorldCatBackendFactory.php index 7f7f72a6b39..2b18022edcb 100644 --- a/module/VuFind/src/VuFind/Search/Factory/WorldCatBackendFactory.php +++ b/module/VuFind/src/VuFind/Search/Factory/WorldCatBackendFactory.php @@ -81,13 +81,10 @@ class WorldCatBackendFactory extends AbstractBackendFactory public function __invoke(ContainerInterface $sm, $name, array $options = null) { $this->setup($sm); - $this->config = $this->serviceLocator - ->get(\VuFind\Config\PluginManager::class) - ->get('config'); - $this->wcConfig = $this->serviceLocator - ->get(\VuFind\Config\PluginManager::class)->get('WorldCat'); + $this->config = $this->getService(\VuFind\Config\PluginManager::class)->get('config'); + $this->wcConfig = $this->getService(\VuFind\Config\PluginManager::class)->get('WorldCat'); if ($this->serviceLocator->has(\VuFind\Log\Logger::class)) { - $this->logger = $this->serviceLocator->get(\VuFind\Log\Logger::class); + $this->logger = $this->getService(\VuFind\Log\Logger::class); } $connector = $this->createConnector(); $backend = $this->createBackend($connector); @@ -146,8 +143,7 @@ protected function createQueryBuilder() */ protected function createRecordCollectionFactory() { - $manager = $this->serviceLocator - ->get(\VuFind\RecordDriver\PluginManager::class); + $manager = $this->getService(\VuFind\RecordDriver\PluginManager::class); $callback = function ($data) use ($manager) { $driver = $manager->get('WorldCat'); $driver->setRawData($data); diff --git a/module/VuFind/src/VuFind/Search/Solr/DeduplicationListener.php b/module/VuFind/src/VuFind/Search/Solr/DeduplicationListener.php index 60a0313744f..67707b17dca 100644 --- a/module/VuFind/src/VuFind/Search/Solr/DeduplicationListener.php +++ b/module/VuFind/src/VuFind/Search/Solr/DeduplicationListener.php @@ -37,6 +37,7 @@ use Laminas\EventManager\EventInterface; use Laminas\EventManager\SharedEventManagerInterface; use Psr\Container\ContainerInterface; +use VuFind\Service\GetServiceTrait; use VuFindSearch\Backend\Solr\Backend; use VuFindSearch\Service; @@ -54,6 +55,8 @@ */ class DeduplicationListener { + use GetServiceTrait; + /** * Backend. * @@ -61,13 +64,6 @@ class DeduplicationListener */ protected $backend; - /** - * Service container. - * - * @var ContainerInterface - */ - protected $serviceLocator; - /** * Search configuration file identifier. * @@ -217,7 +213,7 @@ public function onSearchPost(EventInterface $event) */ protected function fetchLocalRecords($event) { - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class); + $config = $this->getService(\VuFind\Config\PluginManager::class); $dataSourceConfig = $config->get($this->dataSourceConfig); $recordSources = $this->getActiveRecordSources($event); $sourcePriority = $this->determineSourcePriority($recordSources); @@ -343,7 +339,7 @@ function ($a, $b) { */ protected function getActiveRecordSources($event): array { - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class); + $config = $this->getService(\VuFind\Config\PluginManager::class); $searchConfig = $config->get($this->searchConfig); return !empty($searchConfig->Records->sources) ? explode(',', $searchConfig->Records->sources) diff --git a/module/VuFind/src/VuFind/Search/Solr/HierarchicalFacetListener.php b/module/VuFind/src/VuFind/Search/Solr/HierarchicalFacetListener.php index 735f8876fec..104a00c3aef 100644 --- a/module/VuFind/src/VuFind/Search/Solr/HierarchicalFacetListener.php +++ b/module/VuFind/src/VuFind/Search/Solr/HierarchicalFacetListener.php @@ -35,6 +35,7 @@ use Laminas\EventManager\SharedEventManagerInterface; use Laminas\ServiceManager\ServiceLocatorInterface; use VuFind\I18n\TranslatableString; +use VuFind\Service\GetServiceTrait; use VuFindSearch\Backend\BackendInterface; use VuFindSearch\Service; @@ -53,6 +54,8 @@ */ class HierarchicalFacetListener { + use GetServiceTrait; + /** * Backend. * @@ -60,13 +63,6 @@ class HierarchicalFacetListener */ protected $backend; - /** - * Service container. - * - * @var ServiceLocatorInterface - */ - protected $serviceLocator; - /** * Facet configuration. * @@ -126,10 +122,9 @@ public function __construct( $this->backend = $backend; $this->serviceLocator = $serviceLocator; - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class); + $config = $this->getService(\VuFind\Config\PluginManager::class); $this->facetConfig = $config->get($facetConfig); - $this->facetHelper = $this->serviceLocator - ->get(\VuFind\Search\Solr\HierarchicalFacetHelper::class); + $this->facetHelper = $this->getService(\VuFind\Search\Solr\HierarchicalFacetHelper::class); $specialFacets = $this->facetConfig->SpecialFacets; $this->displayStyles diff --git a/module/VuFind/src/VuFind/Service/GetServiceTrait.php b/module/VuFind/src/VuFind/Service/GetServiceTrait.php new file mode 100644 index 00000000000..c21c2ba3c02 --- /dev/null +++ b/module/VuFind/src/VuFind/Service/GetServiceTrait.php @@ -0,0 +1,65 @@ + + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ + +namespace VuFind\Service; + +use Psr\Container\ContainerInterface; + +/** + * Trait implementing generic getter for top-level services. + * + * @category VuFind + * @package Service + * @author Demian Katz + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +trait GetServiceTrait +{ + /** + * Service manager + * + * @var ContainerInterface + */ + protected $serviceLocator; + + /** + * Retrieve a service + * + * @param class-string $name Name of service to retrieve + * + * @template T + * + * @return T + */ + public function getService(string $name) + { + return $this->serviceLocator->get($name); + } +} diff --git a/module/VuFind/src/VuFind/XSLT/Importer.php b/module/VuFind/src/VuFind/XSLT/Importer.php index 2395556f155..a328c6b93b4 100644 --- a/module/VuFind/src/VuFind/XSLT/Importer.php +++ b/module/VuFind/src/VuFind/XSLT/Importer.php @@ -31,6 +31,7 @@ use DOMDocument; use Laminas\ServiceManager\ServiceLocatorInterface; +use VuFind\Service\GetServiceTrait; use VuFindSearch\Backend\Solr\Document\RawXMLDocument; use XSLTProcessor; @@ -47,12 +48,7 @@ */ class Importer { - /** - * Service locator - * - * @var ServiceLocatorInterface - */ - protected $serviceLocator; + use GetServiceTrait; /** * Constructor @@ -86,7 +82,7 @@ public function save( // Save the results (or just display them, if in test mode): if (!$testMode) { - $solr = $this->serviceLocator->get(\VuFind\Solr\Writer::class); + $solr = $this->getService(\VuFind\Solr\Writer::class); $solr->save($index, new RawXMLDocument($xml)); } return $xml; @@ -104,7 +100,7 @@ public function save( protected function generateXML($xmlFile, $properties) { // Load properties file: - $resolver = $this->serviceLocator->get(\VuFind\Config\PathResolver::class); + $resolver = $this->getService(\VuFind\Config\PathResolver::class); $properties = $resolver->getConfigPath($properties, 'import'); if (!file_exists($properties)) { throw new \Exception("Cannot load properties file: {$properties}."); diff --git a/module/VuFindAdmin/src/VuFindAdmin/Controller/AbstractAdmin.php b/module/VuFindAdmin/src/VuFindAdmin/Controller/AbstractAdmin.php index d17a2604eca..2408e812665 100644 --- a/module/VuFindAdmin/src/VuFindAdmin/Controller/AbstractAdmin.php +++ b/module/VuFindAdmin/src/VuFindAdmin/Controller/AbstractAdmin.php @@ -76,8 +76,7 @@ public function validateAccessPermission(MvcEvent $e) // Block access to everyone when module is disabled: $config = $this->getConfig(); if (!isset($config->Site->admin_enabled) || !$config->Site->admin_enabled) { - $pluginManager = $this->serviceLocator - ->get(\Laminas\Mvc\Controller\PluginManager::class); + $pluginManager = $this->getService(\Laminas\Mvc\Controller\PluginManager::class); $redirectPlugin = $pluginManager->get('redirect'); return $redirectPlugin->toRoute('admin/disabled'); } diff --git a/module/VuFindAdmin/src/VuFindAdmin/Controller/AdminController.php b/module/VuFindAdmin/src/VuFindAdmin/Controller/AdminController.php index a877605c32a..c6b83d6fdc2 100644 --- a/module/VuFindAdmin/src/VuFindAdmin/Controller/AdminController.php +++ b/module/VuFindAdmin/src/VuFindAdmin/Controller/AdminController.php @@ -60,7 +60,7 @@ public function homeAction() $config = $this->getConfig(); $xml = false; if (isset($config->Index->url)) { - $response = $this->serviceLocator->get(\VuFindHttp\HttpService::class) + $response = $this->getService(\VuFindHttp\HttpService::class) ->get($config->Index->url . '/admin/cores?wt=xml'); $xml = $response->isSuccess() ? $response->getBody() : false; } diff --git a/module/VuFindAdmin/src/VuFindAdmin/Controller/ConfigController.php b/module/VuFindAdmin/src/VuFindAdmin/Controller/ConfigController.php index 54e761d794c..4bdfb558f97 100644 --- a/module/VuFindAdmin/src/VuFindAdmin/Controller/ConfigController.php +++ b/module/VuFindAdmin/src/VuFindAdmin/Controller/ConfigController.php @@ -49,7 +49,7 @@ public function homeAction() { $view = $this->createViewModel(); $view->setTemplate('admin/config/home'); - $resolver = $this->serviceLocator->get(\VuFind\Config\PathResolver::class); + $resolver = $this->getService(\VuFind\Config\PathResolver::class); $view->baseConfigPath = $resolver->getBaseConfigPath(''); $conf = $this->getConfig(); $view->showInstallLink @@ -64,7 +64,7 @@ public function homeAction() */ public function enableautoconfigAction() { - $resolver = $this->serviceLocator->get(\VuFind\Config\PathResolver::class); + $resolver = $this->getService(\VuFind\Config\PathResolver::class); if (!($configFile = $resolver->getLocalConfigPath('config.ini'))) { $this->flashMessenger()->addErrorMessage( 'Could not enable auto-configuration; local ' @@ -85,8 +85,7 @@ public function enableautoconfigAction() // Reload config now that it has been edited (otherwise, old setting // will persist in cache): - $this->serviceLocator->get(\VuFind\Config\PluginManager::class) - ->reload('config'); + $this->getService(\VuFind\Config\PluginManager::class)->reload('config'); } else { $this->flashMessenger()->addErrorMessage( 'Could not enable auto-configuration; check permissions on ' diff --git a/module/VuFindAdmin/src/VuFindAdmin/Controller/MaintenanceController.php b/module/VuFindAdmin/src/VuFindAdmin/Controller/MaintenanceController.php index 320ca267145..f82ba89796e 100644 --- a/module/VuFindAdmin/src/VuFindAdmin/Controller/MaintenanceController.php +++ b/module/VuFindAdmin/src/VuFindAdmin/Controller/MaintenanceController.php @@ -102,7 +102,7 @@ public function __construct( public function homeAction() { $view = $this->createViewModel(); - $cacheManager = $this->serviceLocator->get(\VuFind\Cache\Manager::class); + $cacheManager = $this->getService(\VuFind\Cache\Manager::class); $view->caches = $cacheManager->getCacheList(); $view->nonPersistentCaches = $cacheManager->getNonPersistentCacheList(); $view->scripts = $this->getScripts(); @@ -118,7 +118,7 @@ public function homeAction() protected function getScripts(): array { // Load the AdminScripts.ini settings - $config = $this->serviceLocator->get(\VuFind\Config\PluginManager::class) + $config = $this->getService(\VuFind\Config\PluginManager::class) ->get('AdminScripts')->toArray(); $globalConfig = $config['Global'] ?? []; unset($config['Global']); @@ -169,7 +169,7 @@ public function scriptAction() public function clearcacheAction() { $cache = null; - $cacheManager = $this->serviceLocator->get(\VuFind\Cache\Manager::class); + $cacheManager = $this->getService(\VuFind\Cache\Manager::class); foreach ($this->params()->fromQuery('cache', []) as $cache) { $cacheManager->getCache($cache)->flush(); } diff --git a/module/VuFindAdmin/src/VuFindAdmin/Controller/OverdriveController.php b/module/VuFindAdmin/src/VuFindAdmin/Controller/OverdriveController.php index aa8945bd7ed..6d6e49a816b 100644 --- a/module/VuFindAdmin/src/VuFindAdmin/Controller/OverdriveController.php +++ b/module/VuFindAdmin/src/VuFindAdmin/Controller/OverdriveController.php @@ -69,8 +69,7 @@ protected function getParam($param) */ public function homeAction() { - $connector = $this->serviceLocator - ->get(\VuFind\DigitalContent\OverdriveConnector::class); + $connector = $this->getService(\VuFind\DigitalContent\OverdriveConnector::class); $view = $this->createViewModel(); $view->setTemplate('admin/overdrive/home'); diff --git a/module/VuFindAdmin/src/VuFindAdmin/Controller/SocialstatsController.php b/module/VuFindAdmin/src/VuFindAdmin/Controller/SocialstatsController.php index 0e2e446cfa3..54c04a12a64 100644 --- a/module/VuFindAdmin/src/VuFindAdmin/Controller/SocialstatsController.php +++ b/module/VuFindAdmin/src/VuFindAdmin/Controller/SocialstatsController.php @@ -57,7 +57,7 @@ public function homeAction() $view->comments = $this->getDbService(CommentsServiceInterface::class)->getStatistics(); $view->ratings = $this->getDbService(RatingsServiceInterface::class)->getStatistics(); $view->favorites = $this->getDbService(UserResourceServiceInterface::class)->getStatistics(); - $view->tags = $this->serviceLocator->get(TagsService::class)->getStatistics(); + $view->tags = $this->getService(TagsService::class)->getStatistics(); return $view; } } diff --git a/module/VuFindAdmin/src/VuFindAdmin/Controller/TagsController.php b/module/VuFindAdmin/src/VuFindAdmin/Controller/TagsController.php index 326a192a153..67aef4a81a8 100644 --- a/module/VuFindAdmin/src/VuFindAdmin/Controller/TagsController.php +++ b/module/VuFindAdmin/src/VuFindAdmin/Controller/TagsController.php @@ -83,7 +83,7 @@ public function homeAction() { $view = $this->createViewModel(); $view->setTemplate('admin/tags/home'); - $view->statistics = $this->serviceLocator->get(TagsService::class)->getStatistics(true); + $view->statistics = $this->getService(TagsService::class)->getStatistics(true); return $view; } @@ -118,7 +118,7 @@ public function listAction() $view->uniqueUsers = $this->getUniqueUsers(); $view->uniqueResources = $this->getUniqueResources(); $page = intval($this->getParam('page', false, '1')); - $view->results = $this->serviceLocator->get(TagsService::class)->getResourceTagsPaginator( + $view->results = $this->getService(TagsService::class)->getResourceTagsPaginator( $this->convertFilter($this->getParam('user_id', false)), $this->convertFilter($this->getParam('resource_id', false)), $this->convertFilter($this->getParam('tag_id', false)), @@ -304,7 +304,7 @@ protected function confirmTagsDelete($ids, $originUrl, $newUrl) */ protected function confirmTagsDeleteByFilter($originUrl, $newUrl) { - $count = $this->serviceLocator->get(TagsService::class)->getResourceTagsPaginator( + $count = $this->getService(TagsService::class)->getResourceTagsPaginator( $this->convertFilter($this->getParam('user_id')), $this->convertFilter($this->getParam('resource_id')), $this->convertFilter($this->getParam('tag_id')) @@ -351,7 +351,7 @@ protected function getUniqueResources(): array */ protected function getUniqueTags(): array { - return $this->serviceLocator->get(TagsService::class)->getUniqueTags( + return $this->getService(TagsService::class)->getUniqueTags( $this->convertFilter($this->getParam('user_id', false)), $this->convertFilter($this->getParam('resource_id', false)), $this->convertFilter($this->getParam('tag_id', false)) diff --git a/module/VuFindApi/src/VuFindApi/Controller/ApiTrait.php b/module/VuFindApi/src/VuFindApi/Controller/ApiTrait.php index d56946697ba..31481b8d57d 100644 --- a/module/VuFindApi/src/VuFindApi/Controller/ApiTrait.php +++ b/module/VuFindApi/src/VuFindApi/Controller/ApiTrait.php @@ -126,8 +126,7 @@ protected function determineOutputMode() */ protected function isAccessDenied($permission) { - $auth = $this->serviceLocator - ->get(\LmcRbacMvc\Service\AuthorizationService::class); + $auth = $this->getService(\LmcRbacMvc\Service\AuthorizationService::class); if (!$auth->isGranted($permission)) { return $this->output( [], diff --git a/module/VuFindApi/src/VuFindApi/Controller/SearchApiController.php b/module/VuFindApi/src/VuFindApi/Controller/SearchApiController.php index 4ea8a5a463a..b7f2ba8d849 100644 --- a/module/VuFindApi/src/VuFindApi/Controller/SearchApiController.php +++ b/module/VuFindApi/src/VuFindApi/Controller/SearchApiController.php @@ -253,7 +253,7 @@ public function recordAction() return $this->output([], self::STATUS_ERROR, 400, 'Missing id'); } - $loader = $this->serviceLocator->get(\VuFind\Record\Loader::class); + $loader = $this->getService(\VuFind\Record\Loader::class); $results = []; try { if (is_array($request['id'])) { @@ -324,7 +324,7 @@ public function searchAction() ? $facetConfig->SpecialFacets->hierarchical->toArray() : []; - $runner = $this->serviceLocator->get(\VuFind\Search\SearchRunner::class); + $runner = $this->getService(\VuFind\Search\SearchRunner::class); try { $results = $runner->run( $request, @@ -410,8 +410,7 @@ protected function getHierarchicalFacetData($facets) $facetResults = $results->getFullFieldFacets($facets, false, -1, 'count'); - $facetHelper = $this->serviceLocator - ->get(\VuFind\Search\Solr\HierarchicalFacetHelper::class); + $facetHelper = $this->getService(\VuFind\Search\Solr\HierarchicalFacetHelper::class); $facetList = []; foreach ($facets as $facet) { diff --git a/module/VuFindDevTools/src/VuFindDevTools/Controller/DevtoolsController.php b/module/VuFindDevTools/src/VuFindDevTools/Controller/DevtoolsController.php index 112ba054baf..2a271a79e8d 100644 --- a/module/VuFindDevTools/src/VuFindDevTools/Controller/DevtoolsController.php +++ b/module/VuFindDevTools/src/VuFindDevTools/Controller/DevtoolsController.php @@ -61,8 +61,7 @@ protected function getQueryBuilder($id) { $command = new \VuFindSearch\Command\GetQueryBuilderCommand($id); try { - $this->serviceLocator->get(\VuFindSearch\Service::class) - ->invoke($command); + $this->getService(\VuFindSearch\Service::class)->invoke($command); } catch (\Exception $e) { return null; } @@ -83,7 +82,7 @@ public function deminifyAction() } if (isset($view->min) && $view->min) { $view->results = $view->min->deminify( - $this->serviceLocator->get(ResultsManager::class) + $this->getService(ResultsManager::class) ); } if (isset($view->results) && $view->results) { @@ -117,7 +116,7 @@ public function homeAction() */ public function iconAction() { - $config = $this->serviceLocator->get(\VuFindTheme\ThemeInfo::class) + $config = $this->getService(\VuFindTheme\ThemeInfo::class) ->getMergedConfig('icons'); $aliases = array_keys($config['aliases'] ?? []); sort($aliases); @@ -133,7 +132,7 @@ public function languageAction() { // Test languages with no local overrides and no fallback: $loader = new ExtendedIni([APPLICATION_PATH . '/languages']); - $langs = $this->serviceLocator->get(LocaleSettings::class) + $langs = $this->getService(LocaleSettings::class) ->getEnabledLocales(); $helper = new LanguageHelper($loader, $langs); return $helper->getAllDetails( From c3fc78dd0b882373c4aa27cf17902bf66df81de3 Mon Sep 17 00:00:00 2001 From: Demian Katz Date: Tue, 30 Jul 2024 13:57:50 -0400 Subject: [PATCH 3/3] Fix bug: passing isn=0 to cover generator caused error. (#3832) --- module/VuFind/src/VuFind/Controller/CoverController.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/module/VuFind/src/VuFind/Controller/CoverController.php b/module/VuFind/src/VuFind/Controller/CoverController.php index 3633a651160..d4603d91713 100644 --- a/module/VuFind/src/VuFind/Controller/CoverController.php +++ b/module/VuFind/src/VuFind/Controller/CoverController.php @@ -106,12 +106,11 @@ protected function getImageParams() // Legacy support for "isn", "isbn" param which has been superseded by isbns: foreach (['isbns', 'isbn', 'isn'] as $identification) { if ($isbns = $params()->fromQuery($identification)) { - $isbns = (array)$isbns; break; } } return [ - 'isbns' => $isbns, + 'isbns' => $isbns ? (array)$isbns : null, 'size' => $params()->fromQuery('size'), 'type' => $params()->fromQuery('contenttype'), 'title' => $params()->fromQuery('title'),