diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index a6ee994906c1202bf9b309b176c716c4f95b4394..22cb8e286a7dbbab765f99f9c1a867e5cd341f90 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -486,12 +486,7 @@ $config = [ ], ], 'search_backend' => [ /* See VuFind\Search\BackendRegistry for defaults */ ], - 'search_options' => [ - 'abstract_factories' => ['VuFind\Search\Options\PluginFactory'], - 'factories' => [ - 'eds' => 'VuFind\Search\Options\Factory::getEDS', - ], - ], + 'search_options' => [ /* See VuFind\Search\Options\PluginManager for defaults */ ], 'search_params' => [ 'abstract_factories' => ['VuFind\Search\Params\PluginFactory'], 'factories' => [ diff --git a/module/VuFind/src/VuFind/Search/EDS/OptionsFactory.php b/module/VuFind/src/VuFind/Search/EDS/OptionsFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..14d4c9515ff81e79778189d3c1c9a4d6c5e22c3c --- /dev/null +++ b/module/VuFind/src/VuFind/Search/EDS/OptionsFactory.php @@ -0,0 +1,73 @@ +<?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]); + } +} diff --git a/module/VuFind/src/VuFind/Search/Options/Factory.php b/module/VuFind/src/VuFind/Search/Options/OptionsFactory.php similarity index 51% rename from module/VuFind/src/VuFind/Search/Options/Factory.php rename to module/VuFind/src/VuFind/Search/Options/OptionsFactory.php index 7ad04cdc5b81a0dfa4ccb99a4ca7ca31549c8af5..7b0214c863e73b1f57781db1511903a8db9e9c7e 100644 --- a/module/VuFind/src/VuFind/Search/Options/Factory.php +++ b/module/VuFind/src/VuFind/Search/Options/OptionsFactory.php @@ -1,10 +1,10 @@ <?php /** - * Search Options Object Factory Class + * Generic factory for search options objects. * * 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,45 +23,43 @@ * @package Search * @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\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 * @package Search * @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 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) - { - $config = $sm->get('VuFind\Config'); - $container = new \Zend\Session\Container( - 'EBSCO', $sm->get('VuFind\SessionManager') + public function __invoke(ContainerInterface $container, $requestedName, + array $options = null + ) { + return new $requestedName( + $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; } } diff --git a/module/VuFind/src/VuFind/Search/Options/PluginManager.php b/module/VuFind/src/VuFind/Search/Options/PluginManager.php index 75dcd6488b9d5584915f47ca1e14d7cb8f63699b..b38bbcbfcd2cd5ef8d5c1b4fbe2948c5ec486ca0 100644 --- a/module/VuFind/src/VuFind/Search/Options/PluginManager.php +++ b/module/VuFind/src/VuFind/Search/Options/PluginManager.php @@ -38,6 +38,81 @@ namespace VuFind\Search\Options; */ 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 * to.