Skip to content
Snippets Groups Projects
Commit 19295556 authored by Demian Katz's avatar Demian Katz
Browse files

Made bootstrap lighter-weight by creating factories instead of instantiating...

Made bootstrap lighter-weight by creating factories instead of instantiating services during plugin manager initialization.  Now objects are instantiated on demand.
parent d8840090
No related merge requests found
...@@ -94,22 +94,23 @@ class Bootstrap ...@@ -94,22 +94,23 @@ class Bootstrap
); );
foreach ($namespaces as $ns) { foreach ($namespaces as $ns) {
$serviceName = 'VuFind\\' . str_replace('\\', '', $ns) . 'PluginManager'; $serviceName = 'VuFind\\' . str_replace('\\', '', $ns) . 'PluginManager';
$className = 'VuFind\\' . $ns . '\PluginManager'; $factory = function ($sm) use ($config, $ns) {
$configKey = strtolower(str_replace('\\', '_', $ns)) . '_plugin_manager'; $className = 'VuFind\\' . $ns . '\PluginManager';
$service = new $className( $configKey = strtolower(str_replace('\\', '_', $ns))
new ServiceManagerConfig($config[$configKey]) . '_plugin_manager';
); return new $className(
if ($service instanceof ServiceLocatorAwareInterface) { new ServiceManagerConfig($config[$configKey])
$service->setServiceLocator($serviceManager); );
} };
$serviceManager->setService($serviceName, $service); $serviceManager->setFactory($serviceName, $factory);
} }
// Set up search manager a little differently -- it is a more complex class // Set up search manager a little differently -- it is a more complex class
// that doesn't work like the other standard plugin managers. // that doesn't work like the other standard plugin managers.
$manager = new \VuFind\Search\Manager($config['search_manager']); $factory = function ($sm) use ($config) {
$manager->setServiceLocator($serviceManager); return new \VuFind\Search\Manager($config['search_manager']);
$serviceManager->setService('SearchManager', $manager); };
$serviceManager->setFactory('SearchManager', $factory);
// TODO: factor out static connection manager. // TODO: factor out static connection manager.
\VuFind\Connection\Manager::setServiceLocator($serviceManager); \VuFind\Connection\Manager::setServiceLocator($serviceManager);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment