From dfdd93bd288f2137b49f2a9d2bb6a4f3a28ac670 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Fri, 26 Sep 2014 10:56:18 -0400 Subject: [PATCH] Do not create services in Bootstrapper. --- module/VuFind/config/module.config.php | 23 ++ module/VuFind/src/VuFind/Bootstrapper.php | 42 --- module/VuFind/src/VuFind/Service/Factory.php | 297 +++++++++++++++++++ 3 files changed, 320 insertions(+), 42 deletions(-) diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index 098e6aef409..9bd7aa12ff4 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -126,30 +126,53 @@ $config = array( 'allow_override' => true, 'factories' => array( 'VuFind\AuthManager' => 'VuFind\Auth\Factory::getManager', + 'VuFind\AuthPluginManager' => 'VuFind\Service\Factory::getAuthPluginManager', + 'VuFind\AutocompletePluginManager' => 'VuFind\Service\Factory::getAutocompletePluginManager', 'VuFind\CacheManager' => 'VuFind\Service\Factory::getCacheManager', 'VuFind\Cart' => 'VuFind\Service\Factory::getCart', + 'VuFind\Config' => 'VuFind\Service\Factory::getConfig', + 'VuFind\ContentPluginManager' => 'VuFind\Service\Factory::getContentPluginManager', + 'VuFind\ContentAuthorNotesPluginManager' => 'VuFind\Service\Factory::getContentAuthorNotesPluginManager', + 'VuFind\ContentCoversPluginManager' => 'VuFind\Service\Factory::getContentCoversPluginManager', + 'VuFind\ContentExcerptsPluginManager' => 'VuFind\Service\Factory::getContentExcerptsPluginManager', + 'VuFind\ContentReviewsPluginManager' => 'VuFind\Service\Factory::getContentReviewsPluginManager', 'VuFind\DateConverter' => 'VuFind\Service\Factory::getDateConverter', 'VuFind\DbAdapter' => 'VuFind\Service\Factory::getDbAdapter', 'VuFind\DbAdapterFactory' => 'VuFind\Service\Factory::getDbAdapterFactory', + 'VuFind\DbTablePluginManager' => 'VuFind\Service\Factory::getDbTablePluginManager', 'VuFind\Export' => 'VuFind\Service\Factory::getExport', + 'VuFind\HierarchyDriverPluginManager' => 'VuFind\Service\Factory::getHierarchyDriverPluginManager', + 'VuFind\HierarchyTreeDataSourcePluginManager' => 'VuFind\Service\Factory::getHierarchyTreeDataSourcePluginManager', + 'VuFind\HierarchyTreeRendererPluginManager' => 'VuFind\Service\Factory::getHierarchyTreeRendererPluginManager', 'VuFind\Http' => 'VuFind\Service\Factory::getHttp', 'VuFind\HMAC' => 'VuFind\Service\Factory::getHMAC', 'VuFind\ILSAuthenticator' => 'VuFind\Auth\Factory::getILSAuthenticator', 'VuFind\ILSConnection' => 'VuFind\Service\Factory::getILSConnection', + 'VuFind\ILSDriverPluginManager' => 'VuFind\Service\Factory::getILSDriverPluginManager', 'VuFind\ILSHoldLogic' => 'VuFind\Service\Factory::getILSHoldLogic', 'VuFind\ILSHoldSettings' => 'VuFind\Service\Factory::getILSHoldSettings', 'VuFind\ILSTitleHoldLogic' => 'VuFind\Service\Factory::getILSTitleHoldLogic', 'VuFind\Logger' => 'VuFind\Service\Factory::getLogger', 'VuFind\Mailer' => 'VuFind\Mailer\Factory', 'VuFind\Recaptcha' => 'VuFind\Service\Factory::getRecaptcha', + 'VuFind\RecommendPluginManager' => 'VuFind\Service\Factory::getRecommendPluginManager', + 'VuFind\RecordDriverPluginManager' => 'VuFind\Service\Factory::getRecordDriverPluginManager', 'VuFind\RecordLoader' => 'VuFind\Service\Factory::getRecordLoader', 'VuFind\RecordRouter' => 'VuFind\Service\Factory::getRecordRouter', 'VuFind\RecordStats' => 'VuFind\Service\Factory::getRecordStats', + 'VuFind\RecordTabPluginManager' => 'VuFind\Service\Factory::getRecordTabPluginManager', + 'VuFind\RelatedPluginManager' => 'VuFind\Service\Factory::getRelatedPluginManager', + 'VuFind\ResolverDriverPluginManager' => 'VuFind\Service\Factory::getResolverDriverPluginManager', 'VuFind\Search\BackendManager' => 'VuFind\Service\Factory::getSearchBackendManager', + 'VuFind\SearchOptionsPluginManager' => 'VuFind\Service\Factory::getSearchOptionsPluginManager', + 'VuFind\SearchParamsPluginManager' => 'VuFind\Service\Factory::getSearchParamsPluginManager', + 'VuFind\SearchResultsPluginManager' => 'VuFind\Service\Factory::getSearchResultsPluginManager', 'VuFind\SearchSpecsReader' => 'VuFind\Service\Factory::getSearchSpecsReader', 'VuFind\SearchStats' => 'VuFind\Service\Factory::getSearchStats', + 'VuFind\SessionPluginManager' => 'VuFind\Service\Factory::getSessionPluginManager', 'VuFind\SMS' => 'VuFind\SMS\Factory', 'VuFind\Solr\Writer' => 'VuFind\Service\Factory::getSolrWriter', + 'VuFind\StatisticsDriverPluginManager' => 'VuFind\Service\Factory::getStatisticsDriverPluginManager', 'VuFind\Tags' => 'VuFind\Service\Factory::getTags', 'VuFind\Translator' => 'VuFind\Service\Factory::getTranslator', 'VuFind\WorldCatUtils' => 'VuFind\Service\Factory::getWorldCatUtils', diff --git a/module/VuFind/src/VuFind/Bootstrapper.php b/module/VuFind/src/VuFind/Bootstrapper.php index d70f3732d59..b40bca078d7 100644 --- a/module/VuFind/src/VuFind/Bootstrapper.php +++ b/module/VuFind/src/VuFind/Bootstrapper.php @@ -97,51 +97,9 @@ class Bootstrapper // Create the configuration manager: $app = $this->event->getApplication(); $serviceManager = $app->getServiceManager(); - $config = $app->getConfig(); - $cfg = new \Zend\ServiceManager\Config($config['vufind']['config_reader']); - $serviceManager->setService( - 'VuFind\Config', new \VuFind\Config\PluginManager($cfg) - ); - - // Use the manager to load the configuration used in subsequent init methods: $this->config = $serviceManager->get('VuFind\Config')->get('config'); } - /** - * Set up plugin managers. - * - * @return void - */ - protected function initPluginManagers() - { - $app = $this->event->getApplication(); - $serviceManager = $app->getServiceManager(); - $config = $app->getConfig(); - - // Use naming conventions to set up a bunch of services based on namespace: - $namespaces = array( - 'Auth', 'Autocomplete', 'Content', 'Content\AuthorNotes', - 'Content\Covers', 'Content\Excerpts', 'Content\Reviews', 'Db\Table', - 'Hierarchy\Driver', 'Hierarchy\TreeDataSource', 'Hierarchy\TreeRenderer', - 'ILS\Driver', 'Recommend', 'RecordDriver', 'RecordTab', 'Related', - 'Resolver\Driver', 'Search\Options', 'Search\Params', 'Search\Results', - 'Session', 'Statistics\Driver' - ); - foreach ($namespaces as $ns) { - $serviceName = 'VuFind\\' . str_replace('\\', '', $ns) . 'PluginManager'; - $factory = function () use ($config, $ns) { - $className = 'VuFind\\' . $ns . '\PluginManager'; - $configKey = strtolower(str_replace('\\', '_', $ns)); - return new $className( - new \Zend\ServiceManager\Config( - $config['vufind']['plugin_managers'][$configKey] - ) - ); - }; - $serviceManager->setFactory($serviceName, $factory); - } - } - /** * Set up the session. This should be done early since other startup routines * may rely on session access. diff --git a/module/VuFind/src/VuFind/Service/Factory.php b/module/VuFind/src/VuFind/Service/Factory.php index b9940351014..327080632a6 100644 --- a/module/VuFind/src/VuFind/Service/Factory.php +++ b/module/VuFind/src/VuFind/Service/Factory.php @@ -40,6 +40,30 @@ use Zend\ServiceManager\ServiceManager; */ class Factory { + /** + * Construct the Auth Plugin Manager. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\Auth\PluginManager + */ + public static function getAuthPluginManager(ServiceManager $sm) + { + return static::getGenericPluginManager($sm, 'Auth'); + } + + /** + * Construct the Autocomplete Plugin Manager. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\Autocomplete\PluginManager + */ + public static function getAutocompletePluginManager(ServiceManager $sm) + { + return static::getGenericPluginManager($sm, 'Autocomplete'); + } + /** * Construct the cache manager. * @@ -74,6 +98,79 @@ class Factory ); } + /** + * Construct the config manager. + * + * @return \VuFind\Config\PluginManager + */ + public static function getConfig(ServiceManager $sm) + { + $config = $sm->get('Config'); + return new \VuFind\Config\PluginManager( + new \Zend\ServiceManager\Config($config['vufind']['config_reader']) + ); + } + + /** + * Construct the Content Plugin Manager. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\Content\PluginManager + */ + public static function getContentPluginManager(ServiceManager $sm) + { + return static::getGenericPluginManager($sm, 'Content'); + } + + /** + * Construct the Content\AuthorNotes Plugin Manager. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\Content\AuthorNotes\PluginManager + */ + public static function getContentAuthorNotesPluginManager(ServiceManager $sm) + { + return static::getGenericPluginManager($sm, 'Content\AuthorNotes'); + } + + /** + * Construct the Content\Covers Plugin Manager. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\Content\Covers\PluginManager + */ + public static function getContentCoversPluginManager(ServiceManager $sm) + { + return static::getGenericPluginManager($sm, 'Content\Covers'); + } + + /** + * Construct the Content\Excerpts Plugin Manager. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\Content\Excerpts\PluginManager + */ + public static function getContentExcerptsPluginManager(ServiceManager $sm) + { + return static::getGenericPluginManager($sm, 'Content\Excerpts'); + } + + /** + * Construct the Content\Reviews Plugin Manager. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\Content\Reviews\PluginManager + */ + public static function getContentReviewsPluginManager(ServiceManager $sm) + { + return static::getGenericPluginManager($sm, 'Content\Reviews'); + } + /** * Construct the date converter. * @@ -114,6 +211,18 @@ class Factory ); } + /** + * Construct the Db\Table Plugin Manager. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\Db\Table\PluginManager + */ + public static function getDbTablePluginManager(ServiceManager $sm) + { + return static::getGenericPluginManager($sm, 'Db\Table'); + } + /** * Construct the export helper. * @@ -129,6 +238,62 @@ class Factory ); } + /** + * Generic plugin manager factory (support method). + * + * @param ServiceManager $sm Service manager. + * @param string $ns VuFind namespace containing plugin manager + * + * @return object + */ + public static function getGenericPluginManager(ServiceManager $sm, $ns) + { + $className = 'VuFind\\' . $ns . '\PluginManager'; + $configKey = strtolower(str_replace('\\', '_', $ns)); + $config = $sm->get('Config'); + return new $className( + new \Zend\ServiceManager\Config( + $config['vufind']['plugin_managers'][$configKey] + ) + ); + } + + /** + * Construct the Hierarchy\Driver Plugin Manager. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\Hierarchy\Driver\PluginManager + */ + public static function getHierarchyDriverPluginManager(ServiceManager $sm) + { + return static::getGenericPluginManager($sm, 'Hierarchy\Driver'); + } + + /** + * Construct the Hierarchy\TreeDataSource Plugin Manager. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\Hierarchy\TreeDataSource\PluginManager + */ + public static function getHierarchyTreeDataSourcePluginManager(ServiceManager $sm) + { + return static::getGenericPluginManager($sm, 'Hierarchy\TreeDataSource'); + } + + /** + * Construct the Hierarchy\TreeRenderer Plugin Manager. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\Hierarchy\TreeRenderer\PluginManager + */ + public static function getHierarchyTreeRendererPluginManager(ServiceManager $sm) + { + return static::getGenericPluginManager($sm, 'Hierarchy\TreeRenderer'); + } + /** * Construct the HTTP service. * @@ -182,6 +347,18 @@ class Factory return $catalog->setHoldConfig($sm->get('VuFind\ILSHoldSettings')); } + /** + * Construct the ILS\Driver Plugin Manager. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\ILS\Driver\PluginManager + */ + public static function getILSDriverPluginManager(ServiceManager $sm) + { + return static::getGenericPluginManager($sm, 'ILS\Driver'); + } + /** * Construct the ILS hold logic. * @@ -290,6 +467,30 @@ class Factory return $recaptcha; } + /** + * Construct the Recommend Plugin Manager. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\Recommend\PluginManager + */ + public static function getRecommendPluginManager(ServiceManager $sm) + { + return static::getGenericPluginManager($sm, 'Recommend'); + } + + /** + * Construct the RecordDriver Plugin Manager. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\RecordDriver\PluginManager + */ + public static function getRecordDriverPluginManager(ServiceManager $sm) + { + return static::getGenericPluginManager($sm, 'RecordDriver'); + } + /** * Construct the record loader. * @@ -336,6 +537,42 @@ class Factory ); } + /** + * Construct the RecordTab Plugin Manager. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\RecordTab\PluginManager + */ + public static function getRecordTabPluginManager(ServiceManager $sm) + { + return static::getGenericPluginManager($sm, 'RecordTab'); + } + + /** + * Construct the Related Plugin Manager. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\Related\PluginManager + */ + public static function getRelatedPluginManager(ServiceManager $sm) + { + return static::getGenericPluginManager($sm, 'Related'); + } + + /** + * Construct the Resolver\Driver Plugin Manager. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\Resolver\Driver\PluginManager + */ + public static function getResolverDriverPluginManager(ServiceManager $sm) + { + return static::getGenericPluginManager($sm, 'Resolver\Driver'); + } + /** * Construct the search backend manager. * @@ -356,6 +593,42 @@ class Factory return $manager; } + /** + * Construct the Search\Options Plugin Manager. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\Search\Options\PluginManager + */ + public static function getSearchOptionsPluginManager(ServiceManager $sm) + { + return static::getGenericPluginManager($sm, 'Search\Options'); + } + + /** + * Construct the Search\Params Plugin Manager. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\Search\Params\PluginManager + */ + public static function getSearchParamsPluginManager(ServiceManager $sm) + { + return static::getGenericPluginManager($sm, 'Search\Params'); + } + + /** + * Construct the Search\Results Plugin Manager. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\Search\Results\PluginManager + */ + public static function getSearchResultsPluginManager(ServiceManager $sm) + { + return static::getGenericPluginManager($sm, 'Search\Results'); + } + /** * Construct the search specs reader. * @@ -386,6 +659,18 @@ class Factory ); } + /** + * Construct the Session Plugin Manager. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\Session\PluginManager + */ + public static function getSessionPluginManager(ServiceManager $sm) + { + return static::getGenericPluginManager($sm, 'Session'); + } + /** * Construct the Solr writer. * @@ -401,6 +686,18 @@ class Factory ); } + /** + * Construct the Statistics\Driver Plugin Manager. + * + * @param ServiceManager $sm Service manager. + * + * @return \VuFind\Statistics\Driver\PluginManager + */ + public static function getStatisticsDriverPluginManager(ServiceManager $sm) + { + return static::getGenericPluginManager($sm, 'Statistics\Driver'); + } + /** * Construct the tag helper. * -- GitLab