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

Modernize search option services.

- Use fully qualified class names as service names.
- Eliminate static factories.
- Move configuration to plugin manager.
parent ed793a34
No related merge requests found
...@@ -486,12 +486,7 @@ $config = [ ...@@ -486,12 +486,7 @@ $config = [
], ],
], ],
'search_backend' => [ /* See VuFind\Search\BackendRegistry for defaults */ ], 'search_backend' => [ /* See VuFind\Search\BackendRegistry for defaults */ ],
'search_options' => [ 'search_options' => [ /* See VuFind\Search\Options\PluginManager for defaults */ ],
'abstract_factories' => ['VuFind\Search\Options\PluginFactory'],
'factories' => [
'eds' => 'VuFind\Search\Options\Factory::getEDS',
],
],
'search_params' => [ 'search_params' => [
'abstract_factories' => ['VuFind\Search\Params\PluginFactory'], 'abstract_factories' => ['VuFind\Search\Params\PluginFactory'],
'factories' => [ 'factories' => [
......
<?php
/**
* Factory for EDS search options objects.
*
* PHP version 5
*
* 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,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package EBSCO
* @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 Wiki
*/
namespace VuFind\Search\EDS;
use Interop\Container\ContainerInterface;
/**
* Factory for EDS search options objects.
*
* @category VuFind
* @package EBSCO
* @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 Wiki
*/
class OptionsFactory extends \VuFind\Search\Options\OptionsFactory
{
/**
* Create an object
*
* @param ContainerInterface $container Service manager
* @param string $requestedName Service being created
* @param null|array $options Extra options (optional)
*
* @return object
*
* @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 function __invoke(ContainerInterface $container, $requestedName,
array $options = null
) {
if (!empty($options)) {
throw new \Exception('Unexpected options sent to factory.');
}
$session = new \Zend\Session\Container(
'EBSCO', $container->get('VuFind\SessionManager')
);
// No API info in session? Re-establish connection:
if (!isset($session->info)) {
$backend = $container->get('VuFind\Search\BackendManager')->get('EDS');
$backend->getSessionToken();
}
return parent::__invoke($container, $requestedName, [$session->info]);
}
}
<?php <?php
/** /**
* Search Options Object Factory Class * Generic factory for search options objects.
* *
* PHP version 5 * 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 * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2, * it under the terms of the GNU General Public License version 2,
...@@ -23,45 +23,43 @@ ...@@ -23,45 +23,43 @@
* @package Search * @package Search
* @author Demian Katz <demian.katz@villanova.edu> * @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @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\Search\Options; namespace VuFind\Search\Options;
use Zend\ServiceManager\ServiceManager; use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Factory\FactoryInterface;
/** /**
* Search Options Object Factory Class * Generic factory for search options objects.
* *
* @category VuFind * @category VuFind
* @package Search * @package Search
* @author Demian Katz <demian.katz@villanova.edu> * @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @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
*
* @codeCoverageIgnore
*/ */
class Factory class OptionsFactory implements FactoryInterface
{ {
/** /**
* Factory for Solr results object. * Create an object
*
* @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 Solr * @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 getEDS(ServiceManager $sm) public function __invoke(ContainerInterface $container, $requestedName,
{ array $options = null
$config = $sm->get('VuFind\Config'); ) {
$container = new \Zend\Session\Container( return new $requestedName(
'EBSCO', $sm->get('VuFind\SessionManager') $container->get('VuFind\Config'), ...($options ?: [])
); );
// No API info in session? Re-establish connection:
if (!isset($container->info)) {
$backend = $sm->get('VuFind\Search\BackendManager')
->get('EDS');
$backend->getSessionToken();
}
$eds = new \VuFind\Search\EDS\Options($config, $container->info);
return $eds;
} }
} }
...@@ -38,6 +38,81 @@ namespace VuFind\Search\Options; ...@@ -38,6 +38,81 @@ namespace VuFind\Search\Options;
*/ */
class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
{ {
/**
* Default plugin aliases.
*
* @var array
*/
protected $aliases = [
'browzine' => 'VuFind\Search\BrowZine\Options',
'combined' => 'VuFind\Search\Combined\Options',
'eds' => 'VuFind\Search\EDS\Options',
'eit' => 'VuFind\Search\EIT\Options',
'emptyset' => 'VuFind\Search\EmptySet\Options',
'favorites' => 'VuFind\Search\Favorites\Options',
'libguides' => 'VuFind\Search\LibGuides\Options',
'mixedlist' => 'VuFind\Search\MixedList\Options',
'pazpar2' => 'VuFind\Search\Pazpar2\Options',
'primo' => 'VuFind\Search\Primo\Options',
'solr' => 'VuFind\Search\Solr\Options',
'solrauth' => 'VuFind\Search\SolrAuth\Options',
'solrauthor' => 'VuFind\Search\SolrAuthor\Options',
'solrauthorfacets' => 'VuFind\Search\SolrAuthorFacets\Options',
'solrcollection' => 'VuFind\Search\SolrCollection\Options',
'solrreserves' => 'VuFind\Search\SolrReserves\Options',
'solrweb' => 'VuFind\Search\SolrWeb\Options',
'summon' => 'VuFind\Search\Summon\Options',
'tags' => 'VuFind\Search\Tags\Options',
'worldcat' => 'VuFind\Search\WorldCat\Options',
];
/**
* Default plugin factories.
*
* @var array
*/
protected $factories = [
'VuFind\Search\BrowZine\Options' => 'VuFind\Search\Options\OptionsFactory',
'VuFind\Search\Combined\Options' => 'VuFind\Search\Options\OptionsFactory',
'VuFind\Search\EDS\Options' => 'VuFind\Search\EDS\OptionsFactory',
'VuFind\Search\EIT\Options' => 'VuFind\Search\Options\OptionsFactory',
'VuFind\Search\EmptySet\Options' => 'VuFind\Search\Options\OptionsFactory',
'VuFind\Search\Favorites\Options' => 'VuFind\Search\Options\OptionsFactory',
'VuFind\Search\LibGuides\Options' => 'VuFind\Search\Options\OptionsFactory',
'VuFind\Search\MixedList\Options' => 'VuFind\Search\Options\OptionsFactory',
'VuFind\Search\Pazpar2\Options' => 'VuFind\Search\Options\OptionsFactory',
'VuFind\Search\Primo\Options' => 'VuFind\Search\Options\OptionsFactory',
'VuFind\Search\Solr\Options' => 'VuFind\Search\Options\OptionsFactory',
'VuFind\Search\SolrAuth\Options' => 'VuFind\Search\Options\OptionsFactory',
'VuFind\Search\SolrAuthor\Options' => 'VuFind\Search\Options\OptionsFactory',
'VuFind\Search\SolrAuthorFacets\Options' =>
'VuFind\Search\Options\OptionsFactory',
'VuFind\Search\SolrCollection\Options' =>
'VuFind\Search\Options\OptionsFactory',
'VuFind\Search\SolrReserves\Options' =>
'VuFind\Search\Options\OptionsFactory',
'VuFind\Search\SolrWeb\Options' => 'VuFind\Search\Options\OptionsFactory',
'VuFind\Search\Summon\Options' => 'VuFind\Search\Options\OptionsFactory',
'VuFind\Search\Tags\Options' => 'VuFind\Search\Options\OptionsFactory',
'VuFind\Search\WorldCat\Options' => 'VuFind\Search\Options\OptionsFactory',
];
/**
* 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\Search\Options\PluginFactory');
parent::__construct($configOrContainerInstance, $v3config);
}
/** /**
* Return the name of the base class or interface that plug-ins must conform * Return the name of the base class or interface that plug-ins must conform
* to. * 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