From 1929555690edb8c328da403e3a7cd877c0ca2d64 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Fri, 19 Oct 2012 11:17:17 -0400 Subject: [PATCH] Made bootstrap lighter-weight by creating factories instead of instantiating services during plugin manager initialization. Now objects are instantiated on demand. --- module/VuFind/src/VuFind/Bootstrap.php | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/module/VuFind/src/VuFind/Bootstrap.php b/module/VuFind/src/VuFind/Bootstrap.php index afa9b0ef9f4..1b32d9ac121 100644 --- a/module/VuFind/src/VuFind/Bootstrap.php +++ b/module/VuFind/src/VuFind/Bootstrap.php @@ -94,22 +94,23 @@ class Bootstrap ); foreach ($namespaces as $ns) { $serviceName = 'VuFind\\' . str_replace('\\', '', $ns) . 'PluginManager'; - $className = 'VuFind\\' . $ns . '\PluginManager'; - $configKey = strtolower(str_replace('\\', '_', $ns)) . '_plugin_manager'; - $service = new $className( - new ServiceManagerConfig($config[$configKey]) - ); - if ($service instanceof ServiceLocatorAwareInterface) { - $service->setServiceLocator($serviceManager); - } - $serviceManager->setService($serviceName, $service); + $factory = function ($sm) use ($config, $ns) { + $className = 'VuFind\\' . $ns . '\PluginManager'; + $configKey = strtolower(str_replace('\\', '_', $ns)) + . '_plugin_manager'; + return new $className( + new ServiceManagerConfig($config[$configKey]) + ); + }; + $serviceManager->setFactory($serviceName, $factory); } // Set up search manager a little differently -- it is a more complex class // that doesn't work like the other standard plugin managers. - $manager = new \VuFind\Search\Manager($config['search_manager']); - $manager->setServiceLocator($serviceManager); - $serviceManager->setService('SearchManager', $manager); + $factory = function ($sm) use ($config) { + return new \VuFind\Search\Manager($config['search_manager']); + }; + $serviceManager->setFactory('SearchManager', $factory); // TODO: factor out static connection manager. \VuFind\Connection\Manager::setServiceLocator($serviceManager); -- GitLab