Skip to content
Snippets Groups Projects
Commit eb57f418 authored by Chris Hallberg's avatar Chris Hallberg Committed by Demian Katz
Browse files

Modernize services for Hierarchy Drivers.

- Switch to new Service Manager 3 format (fully qualified class names as service names).
- Eliminate static factory.
- Move configuration to plugin manager.
parent a992a476
No related merge requests found
......@@ -416,12 +416,7 @@ $config = [
'content_toc' => [ /* see VuFind\Content\TOC\PluginManager for defaults */ ],
'db_row' => [ /* see VuFind\Db\Row\PluginManager for defaults */ ],
'db_table' => [ /* see VuFind\Db\Table\PluginManager for defaults */ ],
'hierarchy_driver' => [
'factories' => [
'default' => 'VuFind\Hierarchy\Driver\Factory::getHierarchyDefault',
'flat' => 'VuFind\Hierarchy\Driver\Factory::getHierarchyFlat',
],
],
'hierarchy_driver' => [ /* see VuFind\Hierarchy\Driver\PluginManager for defaults */ ],
'hierarchy_treedataformatter' => [
'invokables' => [
'json' => 'VuFind\Hierarchy\TreeDataFormatter\Json',
......
......@@ -42,20 +42,28 @@ use Zend\ServiceManager\ServiceManager;
*
* @codeCoverageIgnore
*/
class Factory
class ConfigurationBasedFactory
{
/**
* This constructs a hierarchy driver using VuFind's service setup.
*
* @param \Zend\ServiceManager\ServiceManager $sm Top-level service manager
* @param string $config Name of config to load
* @param string $class Name of driver class
* @param \Zend\ServiceManager\ServiceManager $sm Top-level service m.
* @param string $requestedName Service being built
* @param array|null $options Name of driver class
*
* @return object
*
* @throws Exception if options is populated
*/
public static function get(ServiceManager $sm, $config,
$class = 'VuFind\Hierarchy\Driver\ConfigurationBased'
public function __invoke(ServiceManager $sm, $requestedName,
array $options = null
) {
if (!empty($options)) {
throw new \Exception('Unexpected options passed to factory.');
}
// Get config name from requestedName
$parts = explode('\\', $requestedName);
$config = end($parts);
// Set up options based on global VuFind settings:
$configReader = $sm->get('VuFind\Config');
$globalConfig = $configReader->get('config');
......@@ -68,35 +76,11 @@ class Factory
$driverConfig = $configReader->get($config);
// Build object:
return new $class(
return new ConfigurationBased(
$driverConfig,
$sm->get('VuFind\HierarchyTreeDataSourcePluginManager'),
$sm->get('VuFind\HierarchyTreeRendererPluginManager'),
$options
);
}
/**
* Factory for HierarchyDefault to be called from module.config.php.
*
* @param ServiceManager $sm Service manager.
*
* @return HierarchyDefault
*/
public static function getHierarchyDefault(ServiceManager $sm)
{
return static::get($sm, 'HierarchyDefault');
}
/**
* Factory for HierarchyFlat to be called from module.config.php.
*
* @param ServiceManager $sm Service manager.
*
* @return HierarchyFlat
*/
public static function getHierarchyFlat(ServiceManager $sm)
{
return static::get($sm, 'HierarchyFlat');
}
}
......@@ -38,6 +38,28 @@ namespace VuFind\Hierarchy\Driver;
*/
class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
{
/**
* Default plugin aliases.
*
* @var array
*/
protected $aliases = [
'default' => 'VuFind\Hierarchy\Driver\HierarchyDefault',
'flat' => 'VuFind\Hierarchy\Driver\HierarchyFlat',
];
/**
* Default plugin factories.
*
* @var array
*/
protected $factories = [
'VuFind\Hierarchy\Driver\HierarchyDefault' =>
'VuFind\Hierarchy\Driver\ConfigurationBasedFactory',
'VuFind\Hierarchy\Driver\HierarchyFlat' =>
'VuFind\Hierarchy\Driver\ConfigurationBasedFactory',
];
/**
* Return the name of the base class or interface that plug-ins must conform
* to.
......
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