From 65d212234e2bf121b3b44deef131987c11d06524 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Tue, 28 Aug 2012 10:52:48 -0400 Subject: [PATCH] Replaced explicit object construction in Bootstrap class with service manager configuration. --- module/VuFind/config/module.config.php | 6 ++++++ module/VuFind/src/VuFind/Bootstrap.php | 20 ++++++-------------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index e440fd3d6c0..14fb124005e 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -100,6 +100,12 @@ $config = array( 'result-scroller' => 'VuFind\Controller\Plugin\ResultScroller', ) ), + 'service_manager' => array( + 'invokables' => array( + 'authmanager' => 'VuFind\Auth\Manager', + 'sessionmanager' => 'Zend\Session\SessionManager', + ) + ), 'translator' => array(), 'view_manager' => array( 'display_not_found_reason' => APPLICATION_ENV == 'development', diff --git a/module/VuFind/src/VuFind/Bootstrap.php b/module/VuFind/src/VuFind/Bootstrap.php index e0bc7b16b10..ddc785c468a 100644 --- a/module/VuFind/src/VuFind/Bootstrap.php +++ b/module/VuFind/src/VuFind/Bootstrap.php @@ -26,13 +26,12 @@ * @link http://vufind.org Main Site */ namespace VuFind; -use VuFind\Auth\Manager as AuthManager, VuFind\Config\Reader as ConfigReader, +use VuFind\Config\Reader as ConfigReader, VuFind\Db\AdapterFactory as DbAdapterFactory, VuFind\Logger, VuFind\Theme\Initializer as ThemeInitializer, VuFind\Translator\Translator, Zend\Console\Console, Zend\Db\TableGateway\Feature\GlobalAdapterFeature as DbGlobalAdapter, - Zend\Mvc\MvcEvent, Zend\Mvc\Router\Http\RouteMatch, - Zend\Session\SessionManager; + Zend\Mvc\MvcEvent, Zend\Mvc\Router\Http\RouteMatch; /** * VuFind Bootstrapper @@ -107,9 +106,8 @@ class Bootstrap } // Register a session manager in the service manager: - $sessionManager = new SessionManager(); $serviceManager = $this->event->getApplication()->getServiceManager(); - $serviceManager->setService('SessionManager', $sessionManager); + $sessionManager = $serviceManager->get('SessionManager'); // Set up session handler (after manipulating the type setting for legacy // compatibility -- VuFind 1.x used MySQL instead of Database and had @@ -178,17 +176,11 @@ class Bootstrap */ protected function initAccount() { - $authManager = new AuthManager(); - - // Register in service manager: + // Retrieve from service manager: $serviceManager = $this->event->getApplication()->getServiceManager(); - $serviceManager->setService('AuthManager', $authManager); - - // ...and register service manager in AuthManager (for access to other - // services, such as the session manager): - $authManager->setServiceLocator($serviceManager); + $authManager = $serviceManager->get('AuthManager'); - // Now that we're all set up, make sure credentials haven't expired: + // Make sure credentials haven't expired: $authManager->checkForExpiredCredentials(); // Register in view: -- GitLab