From e5b949081d95d532fc4945da88eed26baec1f541 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Wed, 27 Feb 2013 13:28:33 -0500 Subject: [PATCH] Created getConfig convenience method in base controller; used this to eliminate several Config\Reader calls. --- .../VuFind/src/VuFind/Controller/AbstractBase.php | 12 ++++++++++++ .../src/VuFind/Controller/AbstractRecord.php | 2 +- .../src/VuFind/Controller/AdminController.php | 8 ++++---- .../src/VuFind/Controller/AjaxController.php | 7 +++---- .../VuFind/Controller/AlphabrowseController.php | 5 ++--- .../src/VuFind/Controller/CartController.php | 2 +- .../src/VuFind/Controller/CoverController.php | 4 ++-- .../src/VuFind/Controller/HierarchyController.php | 2 +- .../src/VuFind/Controller/IndexController.php | 4 +--- .../src/VuFind/Controller/InstallController.php | 14 +++++++------- .../src/VuFind/Controller/MyResearchController.php | 5 ++--- .../VuFind/src/VuFind/Controller/OaiController.php | 3 +-- .../src/VuFind/Controller/SearchController.php | 11 +++++------ 13 files changed, 42 insertions(+), 37 deletions(-) diff --git a/module/VuFind/src/VuFind/Controller/AbstractBase.php b/module/VuFind/src/VuFind/Controller/AbstractBase.php index 106dd6e4a9f..b2dfb7efd18 100644 --- a/module/VuFind/src/VuFind/Controller/AbstractBase.php +++ b/module/VuFind/src/VuFind/Controller/AbstractBase.php @@ -176,6 +176,18 @@ class AbstractBase extends AbstractActionController return $patron; } + /** + * Get a VuFind configuration. + * + * @param string $id Configuration identifier (default = main VuFind config) + * + * @return \Zend\Config\Config + */ + public function getConfig($id = 'config') + { + return $this->getServiceLocator()->get('VuFind\Config')->get($id); + } + /** * Get the ILS connection. * diff --git a/module/VuFind/src/VuFind/Controller/AbstractRecord.php b/module/VuFind/src/VuFind/Controller/AbstractRecord.php index fdd84b6db3b..1b5bd949c8b 100644 --- a/module/VuFind/src/VuFind/Controller/AbstractRecord.php +++ b/module/VuFind/src/VuFind/Controller/AbstractRecord.php @@ -345,7 +345,7 @@ class AbstractRecord extends AbstractBase public function emailAction() { // Force login if necessary: - $config = \VuFind\Config\Reader::getConfig(); + $config = $this->getConfig(); if ((!isset($config->Mail->require_login) || $config->Mail->require_login) && !$this->getUser() ) { diff --git a/module/VuFind/src/VuFind/Controller/AdminController.php b/module/VuFind/src/VuFind/Controller/AdminController.php index 8097f5c8965..592cb9a10c7 100644 --- a/module/VuFind/src/VuFind/Controller/AdminController.php +++ b/module/VuFind/src/VuFind/Controller/AdminController.php @@ -61,7 +61,7 @@ class AdminController extends AbstractBase } // Block access to everyone when module is disabled: - $config = ConfigReader::getConfig(); + $config = $this->getConfig(); if (!isset($config->Site->admin_enabled) || !$config->Site->admin_enabled) { $routeMatch->setParam('action', 'disabled'); return; @@ -127,7 +127,7 @@ class AdminController extends AbstractBase */ public function homeAction() { - $config = ConfigReader::getConfig(); + $config = $this->getConfig(); $xml = false; if (isset($config->Index->url)) { $response = $this->getServiceLocator()->get('VuFind\Http') @@ -162,7 +162,7 @@ class AdminController extends AbstractBase { $view = $this->createViewModel(); - $config = ConfigReader::getConfig(); + $config = $this->getConfig(); $statsFilled = array( 'search' => false, 'record' => false @@ -240,7 +240,7 @@ class AdminController extends AbstractBase { $view = $this->createViewModel(); $view->baseConfigPath = ConfigReader::getBaseConfigPath(''); - $conf = ConfigReader::getConfig(); + $conf = $this->getConfig(); $view->showInstallLink = isset($conf->System->autoConfigure) && $conf->System->autoConfigure; return $view; diff --git a/module/VuFind/src/VuFind/Controller/AjaxController.php b/module/VuFind/src/VuFind/Controller/AjaxController.php index 5d19f4e1248..04d3287c9b9 100644 --- a/module/VuFind/src/VuFind/Controller/AjaxController.php +++ b/module/VuFind/src/VuFind/Controller/AjaxController.php @@ -26,8 +26,7 @@ * @link http://vufind.org/wiki/vufind2:building_a_controller Wiki */ namespace VuFind\Controller; -use VuFind\Config\Reader as ConfigReader, - VuFind\Exception\Auth as AuthException; +use VuFind\Exception\Auth as AuthException; /** * This controller handles global AJAX functionality @@ -209,7 +208,7 @@ class AjaxController extends AbstractBase ); // Load callnumber and location settings: - $config = ConfigReader::getConfig(); + $config = $this->getConfig(); $callnumberSetting = isset($config->Item_Status->multiple_call_nos) ? $config->Item_Status->multiple_call_nos : 'msg'; $locationSetting = isset($config->Item_Status->multiple_locations) @@ -1257,7 +1256,7 @@ class AjaxController extends AbstractBase $this->writeSession(); // avoid session write timing bug $openUrl = $this->params()->fromQuery('openurl', ''); - $config = ConfigReader::getConfig(); + $config = $this->getConfig(); $resolverType = isset($config->OpenURL->resolver) ? $config->OpenURL->resolver : 'other'; $pluginManager = $this->getServiceLocator() diff --git a/module/VuFind/src/VuFind/Controller/AlphabrowseController.php b/module/VuFind/src/VuFind/Controller/AlphabrowseController.php index 0c91ade93bc..48746be06c8 100644 --- a/module/VuFind/src/VuFind/Controller/AlphabrowseController.php +++ b/module/VuFind/src/VuFind/Controller/AlphabrowseController.php @@ -27,8 +27,7 @@ * @link http://vufind.org/wiki/alphabetical_heading_browse Wiki */ namespace VuFind\Controller; -use VuFind\Config\Reader as ConfigReader, - VuFind\Connection\Manager as ConnectionManager, +use VuFind\Connection\Manager as ConnectionManager, VuFind\Exception\Solr as SolrException; /** @@ -52,7 +51,7 @@ class AlphabrowseController extends AbstractBase */ public function homeAction() { - $config = ConfigReader::getConfig(); + $config = $this->getConfig(); // Load browse types from config file, or use defaults if unavailable: if (isset($config->AlphaBrowse_Types) diff --git a/module/VuFind/src/VuFind/Controller/CartController.php b/module/VuFind/src/VuFind/Controller/CartController.php index cd8895959c9..f2fb501a8d8 100644 --- a/module/VuFind/src/VuFind/Controller/CartController.php +++ b/module/VuFind/src/VuFind/Controller/CartController.php @@ -167,7 +167,7 @@ class CartController extends AbstractBase public function emailAction() { // Force login if necessary: - $config = \VuFind\Config\Reader::getConfig(); + $config = $this->getConfig(); if ((!isset($config->Mail->require_login) || $config->Mail->require_login) && !$this->getUser() ) { diff --git a/module/VuFind/src/VuFind/Controller/CoverController.php b/module/VuFind/src/VuFind/Controller/CoverController.php index 60508d259ac..2efe5dae265 100644 --- a/module/VuFind/src/VuFind/Controller/CoverController.php +++ b/module/VuFind/src/VuFind/Controller/CoverController.php @@ -26,7 +26,7 @@ * @link http://www.vufind.org Main Page */ namespace VuFind\Controller; -use VuFind\Config\Reader as ConfigReader, VuFind\Cover\Loader; +use VuFind\Cover\Loader; /** * Generates covers for book entries @@ -51,7 +51,7 @@ class CoverController extends AbstractBase // Construct object for loading cover images if it does not already exist: if (!$this->loader) { $this->loader = new Loader( - ConfigReader::getConfig(), + $this->getConfig(), $this->getServiceLocator()->get('VuFindTheme\ThemeInfo'), $this->getServiceLocator()->get('VuFind\Http')->createClient(), $this->getServiceLocator()->get('VuFind\CacheManager')->getCacheDir() diff --git a/module/VuFind/src/VuFind/Controller/HierarchyController.php b/module/VuFind/src/VuFind/Controller/HierarchyController.php index a1b6c5a3c3f..0fae2b3587e 100644 --- a/module/VuFind/src/VuFind/Controller/HierarchyController.php +++ b/module/VuFind/src/VuFind/Controller/HierarchyController.php @@ -79,7 +79,7 @@ class HierarchyController extends AbstractBase public function searchtreeAction() { $this->writeSession(); // avoid session write timing bug - $config = \VuFind\Config\Reader::getConfig(); + $config = $this->getConfig(); $limit = isset($config->Hierarchy->treeSearchLimit) ? $config->Hierarchy->treeSearchLimit : -1; $resultIDs = array(); diff --git a/module/VuFind/src/VuFind/Controller/IndexController.php b/module/VuFind/src/VuFind/Controller/IndexController.php index 17c52e526e8..ac6f7a3d2fa 100644 --- a/module/VuFind/src/VuFind/Controller/IndexController.php +++ b/module/VuFind/src/VuFind/Controller/IndexController.php @@ -27,8 +27,6 @@ */ namespace VuFind\Controller; -use VuFind\Config\Reader as ConfigReader; - /** * Redirects the user to the appropriate default VuFind action. * @@ -48,7 +46,7 @@ class IndexController extends AbstractBase */ public function homeAction() { - $config = ConfigReader::getConfig(); + $config = $this->getConfig(); $loggedInModule = isset($config->Site->defaultLoggedInModule) ? $config->Site->defaultLoggedInModule : 'MyResearch'; $loggedOutModule = isset($config->Site->defaultModule) diff --git a/module/VuFind/src/VuFind/Controller/InstallController.php b/module/VuFind/src/VuFind/Controller/InstallController.php index 0cb93d909fa..cf4600a8091 100644 --- a/module/VuFind/src/VuFind/Controller/InstallController.php +++ b/module/VuFind/src/VuFind/Controller/InstallController.php @@ -56,7 +56,7 @@ class InstallController extends AbstractBase { // If auto-configuration is disabled, prevent any other action from being // accessed: - $config = ConfigReader::getConfig(); + $config = $this->getConfig(); if (!isset($config->System->autoConfigure) || !$config->System->autoConfigure ) { @@ -115,7 +115,7 @@ class InstallController extends AbstractBase // See if the URL setting remains at the default (unless we already // know we've failed): if ($status) { - $config = ConfigReader::getConfig(); + $config = $this->getConfig(); if (stristr($config->Site->url, 'myuniversity.edu')) { $status = false; } @@ -428,7 +428,7 @@ class InstallController extends AbstractBase */ protected function checkILS() { - $config = ConfigReader::getConfig(); + $config = $this->getConfig(); if (in_array($config->Catalog->driver, array('Sample', 'Demo'))) { $status = false; } else { @@ -473,7 +473,7 @@ class InstallController extends AbstractBase // If we got this far, check whether we have an error with a real driver // or if we need to warn the user that they have selected a fake driver: - $config = ConfigReader::getConfig(); + $config = $this->getConfig(); $view = $this->createViewModel(); if (in_array($config->Catalog->driver, array('Sample', 'Demo'))) { $view->demo = true; @@ -526,7 +526,7 @@ class InstallController extends AbstractBase public function fixsolrAction() { // In Windows, localhost may fail -- see if switching to 127.0.0.1 helps: - $config = ConfigReader::getConfig(); + $config = $this->getConfig(); $configFile = ConfigReader::getLocalConfigPath('config.ini', null, true); if (stristr($config->Index->url, 'localhost')) { $newUrl = str_replace('localhost', '127.0.0.1', $config->Index->url); @@ -569,7 +569,7 @@ class InstallController extends AbstractBase protected function checkSecurity() { // Are configuration settings missing? - $config = ConfigReader::getConfig(); + $config = $this->getConfig(); if (!isset($config->Authentication->hash_passwords) || !$config->Authentication->hash_passwords || !isset($config->Authentication->encrypt_ils_password) @@ -665,7 +665,7 @@ class InstallController extends AbstractBase public function performsecurityfixAction() { // First, set encryption/hashing to true, and set the key - $config = ConfigReader::getConfig(); + $config = $this->getConfig(); $configPath = ConfigReader::getLocalConfigPath('config.ini', null, true); $writer = new ConfigWriter($configPath); if ($this->fixSecurityConfiguration($config, $writer)) { diff --git a/module/VuFind/src/VuFind/Controller/MyResearchController.php b/module/VuFind/src/VuFind/Controller/MyResearchController.php index 23daa5ddf49..ed5699b9231 100644 --- a/module/VuFind/src/VuFind/Controller/MyResearchController.php +++ b/module/VuFind/src/VuFind/Controller/MyResearchController.php @@ -27,8 +27,7 @@ */ namespace VuFind\Controller; -use VuFind\Config\Reader as ConfigReader, - VuFind\Exception\Auth as AuthException, +use VuFind\Exception\Auth as AuthException, VuFind\Exception\ListPermission as ListPermissionException, VuFind\Exception\RecordMissing as RecordMissingException, Zend\Stdlib\Parameters; @@ -81,7 +80,7 @@ class MyResearchController extends AbstractBase return $this->redirect()->toUrl($url); } - $config = ConfigReader::getConfig(); + $config = $this->getConfig(); $page = isset($config->Site->defaultAccountPage) ? $config->Site->defaultAccountPage : 'Favorites'; return $this->forwardTo('MyResearch', $page); diff --git a/module/VuFind/src/VuFind/Controller/OaiController.php b/module/VuFind/src/VuFind/Controller/OaiController.php index 653d714df0c..2ce781103c7 100644 --- a/module/VuFind/src/VuFind/Controller/OaiController.php +++ b/module/VuFind/src/VuFind/Controller/OaiController.php @@ -26,7 +26,6 @@ * @link http://vufind.org/wiki/vufind2:building_a_controller Wiki */ namespace VuFind\Controller; -use VuFind\Config\Reader as ConfigReader; /** * OAIController Class @@ -82,7 +81,7 @@ class OaiController extends AbstractBase protected function handleOAI($serverClass) { // Check if the OAI Server is enabled before continuing - $config = ConfigReader::getConfig(); + $config = $this->getConfig(); $response = $this->getResponse(); if (!isset($config->OAI)) { $response->setStatusCode(404); diff --git a/module/VuFind/src/VuFind/Controller/SearchController.php b/module/VuFind/src/VuFind/Controller/SearchController.php index fcf2fadb56e..9d6ed37f24e 100644 --- a/module/VuFind/src/VuFind/Controller/SearchController.php +++ b/module/VuFind/src/VuFind/Controller/SearchController.php @@ -27,8 +27,7 @@ */ namespace VuFind\Controller; -use VuFind\Config\Reader as ConfigReader, - VuFind\Exception\Mail as MailException, VuFind\Search\Memory, +use VuFind\Exception\Mail as MailException, VuFind\Search\Memory, VuFind\Solr\Utils as SolrUtils; /** @@ -85,7 +84,7 @@ class SearchController extends AbstractSearch ); // Force login if necessary: - $config = \VuFind\Config\Reader::getConfig(); + $config = $this->getConfig(); if ((!isset($config->Mail->require_login) || $config->Mail->require_login) && !$this->getUser() ) { @@ -311,7 +310,7 @@ class SearchController extends AbstractSearch // Find out if there are user configured range options; if not, // default to the standard 1/5/30 days: $ranges = array(); - $searchSettings = ConfigReader::getConfig('searches'); + $searchSettings = $this->getConfig('searches'); if (isset($searchSettings->NewItem->ranges)) { $tmp = explode(',', $searchSettings->NewItem->ranges); foreach ($tmp as $range) { @@ -342,7 +341,7 @@ class SearchController extends AbstractSearch $range = $this->params()->fromQuery('range'); $dept = $this->params()->fromQuery('department'); - $searchSettings = ConfigReader::getConfig('searches'); + $searchSettings = $this->getConfig('searches'); // The code always pulls in enough catalog results to get a fixed number // of pages worth of Solr results. Note that if the Solr index is out of @@ -583,7 +582,7 @@ class SearchController extends AbstractSearch { switch ($this->params()->fromQuery('method')) { case 'describe': - $config = ConfigReader::getConfig(); + $config = $this->getConfig(); $xml = $this->getViewRenderer()->render( 'search/opensearch-describe.phtml', array('site' => $config->Site) ); -- GitLab