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

Modernize resolver driver service configuration.

- Use fully qualified class names as service names.
- Move configuration to plugin manager.
- Eliminate static factories.
parent 608aa4c1
No related merge requests found
......@@ -446,21 +446,7 @@ $config = [
'recorddriver' => [ /* See VuFind\RecordDriver\PluginManager for defaults */ ],
'recordtab' => [ /* See VuFind\RecordTab\PluginManager for defaults */ ],
'related' => [ /* See VuFind\Related\PluginManager for defaults */ ],
'resolver_driver' => [
'abstract_factories' => ['VuFind\Resolver\Driver\PluginFactory'],
'factories' => [
'360link' => 'VuFind\Resolver\Driver\Factory::getThreesixtylink',
'ezb' => 'VuFind\Resolver\Driver\Factory::getEzb',
'sfx' => 'VuFind\Resolver\Driver\Factory::getSfx',
'redi' => 'VuFind\Resolver\Driver\Factory::getRedi',
],
'invokables' => [
'demo' => 'VuFind\Resolver\Driver\Demo',
],
'aliases' => [
'threesixtylink' => '360link',
],
],
'resolver_driver' => [ /* See VuFind\Resolver\Driver\PluginManager for defaults */ ],
'search_backend' => [ /* See VuFind\Search\BackendRegistry for defaults */ ],
'search_options' => [ /* See VuFind\Search\Options\PluginManager for defaults */ ],
'search_params' => [ /* See VuFind\Search\Params\PluginManager for defaults */ ],
......
<?php
/**
* Resolver Driver Factory Class
* Generic factory suitable for most resolver drivers.
*
* PHP version 5
*
* Copyright (C) Villanova University 2014.
* Copyright (C) Villanova University 2018.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
......@@ -23,86 +23,46 @@
* @package Resolver_Drivers
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development:plugins:hierarchy_components Wiki
* @link https://vufind.org/wiki/development Wiki
*/
namespace VuFind\Resolver\Driver;
use Zend\ServiceManager\ServiceManager;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Factory\FactoryInterface;
/**
* Resolver Driver Factory Class
* Generic factory suitable for most resolver drivers.
*
* @category VuFind
* @package Resolver_Drivers
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development:plugins:hierarchy_components Wiki
*
* @codeCoverageIgnore
* @link https://vufind.org/wiki/development Wiki
*/
class Factory
class DriverWithHttpClientFactory implements FactoryInterface
{
/**
* Factory for Threesixtylink record driver.
*
* @param ServiceManager $sm Service manager.
*
* @return Threesixtylink
*/
public static function getThreesixtylink(ServiceManager $sm)
{
$config = $sm->get('VuFind\Config')->get('config');
return new Threesixtylink(
$config->OpenURL->url,
$sm->get('VuFind\Http')->createClient()
);
}
/**
* Factory for Ezb record driver.
*
* @param ServiceManager $sm Service manager.
*
* @return Ezb
*/
public static function getEzb(ServiceManager $sm)
{
$config = $sm->get('VuFind\Config')->get('config');
return new Ezb(
$config->OpenURL->url,
$sm->get('VuFind\Http')->createClient()
);
}
/**
* Factory for Sfx record driver.
*
* @param ServiceManager $sm Service manager.
* Create an object
*
* @return Sfx
*/
public static function getSfx(ServiceManager $sm)
{
$config = $sm->get('VuFind\Config')->get('config');
return new Sfx(
$config->OpenURL->url,
$sm->get('VuFind\Http')->createClient()
);
}
/**
* Factory for Redi record driver.
* @param ContainerInterface $container Service manager
* @param string $requestedName Service being created
* @param null|array $options Extra options (optional)
*
* @param ServiceManager $sm Service manager.
* @return object
*
* @return Redi
* @throws ServiceNotFoundException if unable to resolve the service.
* @throws ServiceNotCreatedException if an exception is raised when
* creating a service.
* @throws ContainerException if any other error occurs
*/
public static function getRedi(ServiceManager $sm)
{
$config = $sm->get('VuFind\Config')->get('config');
return new Redi(
public function __invoke(ContainerInterface $container, $requestedName,
array $options = null
) {
$config = $container->get('VuFind\Config')->get('config');
return new $requestedName(
$config->OpenURL->url,
$sm->get('VuFind\Http')->createClient()
$container->get('VuFind\Http')->createClient(),
...($options ?: [])
);
}
}
......@@ -38,6 +38,54 @@ namespace VuFind\Resolver\Driver;
*/
class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
{
/**
* Default plugin aliases.
*
* @var array
*/
protected $aliases = [
'360link' => 'VuFind\Resolver\Driver\Threesixtylink',
'demo' => 'VuFind\Resolver\Driver\Demo',
'ezb' => 'VuFind\Resolver\Driver\Ezb',
'sfx' => 'VuFind\Resolver\Driver\Sfx',
'redi' => 'VuFind\Resolver\Driver\Redi',
'threesixtylink' => 'VuFind\Resolver\Driver\Threesixtylink',
];
/**
* Default plugin factories.
*
* @var array
*/
protected $factories = [
'VuFind\Resolver\Driver\Threesixtylink' =>
'VuFind\Resolver\Driver\DriverWithHttpClientFactory',
'VuFind\Resolver\Driver\Demo' =>
'Zend\ServiceManager\Factory\InvokableFactory',
'VuFind\Resolver\Driver\Ezb' =>
'VuFind\Resolver\Driver\DriverWithHttpClientFactory',
'VuFind\Resolver\Driver\Sfx' =>
'VuFind\Resolver\Driver\DriverWithHttpClientFactory',
'VuFind\Resolver\Driver\Redi' =>
'VuFind\Resolver\Driver\DriverWithHttpClientFactory',
];
/**
* Constructor
*
* Make sure plugins are properly initialized.
*
* @param mixed $configOrContainerInstance Configuration or container instance
* @param array $v3config If $configOrContainerInstance is a
* container, this value will be passed to the parent constructor.
*/
public function __construct($configOrContainerInstance = null,
array $v3config = []
) {
$this->addAbstractFactory('VuFind\Resolver\Driver\PluginFactory');
parent::__construct($configOrContainerInstance, $v3config);
}
/**
* 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