diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index fbbc46d9f2fc772ee5fe5be15dc2acdcaf640036..a6ee994906c1202bf9b309b176c716c4f95b4394 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -469,18 +469,7 @@ $config = [ 'ZfcRbac\Initializer\AuthorizationServiceInitializer' ], ], - 'related' => [ - 'abstract_factories' => ['VuFind\Related\PluginFactory'], - 'factories' => [ - 'similar' => 'VuFind\Related\Factory::getSimilar', - 'worldcatsimilar' => 'VuFind\Related\Factory::getWorldCatSimilar', - ], - 'invokables' => [ - 'channels' => 'VuFind\Related\Channels', - 'editions' => 'VuFind\Related\Deprecated', - 'worldcateditions' => 'VuFind\Related\Deprecated', - ], - ], + 'related' => [ /* See VuFind\Related\PluginManager for defaults */ ], 'resolver_driver' => [ 'abstract_factories' => ['VuFind\Resolver\Driver\PluginFactory'], 'factories' => [ diff --git a/module/VuFind/src/VuFind/Related/Factory.php b/module/VuFind/src/VuFind/Related/Factory.php deleted file mode 100644 index 932b44c328eec91a004e9c6f15bc798ec8aa5efc..0000000000000000000000000000000000000000 --- a/module/VuFind/src/VuFind/Related/Factory.php +++ /dev/null @@ -1,98 +0,0 @@ -<?php -/** - * Related Record Module Factory Class - * - * PHP version 5 - * - * Copyright (C) Villanova University 2014. - * - * 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 Related_Records - * @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 - */ -namespace VuFind\Related; - -use Zend\ServiceManager\ServiceManager; - -/** - * Related Record Module Factory Class - * - * @category VuFind - * @package Related_Records - * @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 - */ -class Factory -{ - /** - * Factory for Editions module. - * - * @param ServiceManager $sm Service manager. - * - * @return Editions - */ - public static function getEditions(ServiceManager $sm) - { - return new Editions( - $sm->get('VuFind\SearchResultsPluginManager'), - $sm->get('VuFind\WorldCatUtils') - ); - } - - /** - * Factory for Similar module. - * - * @param ServiceManager $sm Service manager. - * - * @return Similar - */ - public static function getSimilar(ServiceManager $sm) - { - return new Similar($sm->get('VuFind\Search')); - } - - /** - * Factory for WorldCatEditions module. - * - * @param ServiceManager $sm Service manager. - * - * @return WorldCatEditions - */ - public static function getWorldCatEditions(ServiceManager $sm) - { - return new WorldCatEditions( - $sm->get('VuFind\SearchResultsPluginManager'), - $sm->get('VuFind\WorldCatUtils') - ); - } - - /** - * Factory for WorldCatSimilar module. - * - * @param ServiceManager $sm Service manager. - * - * @return WorldCatSimilar - */ - public static function getWorldCatSimilar(ServiceManager $sm) - { - return new WorldCatSimilar($sm->get('VuFind\Search')); - } -} diff --git a/module/VuFind/src/VuFind/Related/PluginManager.php b/module/VuFind/src/VuFind/Related/PluginManager.php index 48be182c15666f574d20fd84bde3339381ddaf19..7d5d84b84251d66abc9491a97a4570672060f102 100644 --- a/module/VuFind/src/VuFind/Related/PluginManager.php +++ b/module/VuFind/src/VuFind/Related/PluginManager.php @@ -38,6 +38,32 @@ namespace VuFind\Related; */ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager { + /** + * Default plugin aliases. + * + * @var array + */ + protected $aliases = [ + 'channels' => 'VuFind\Related\Channels', + 'editions' => 'VuFind\Related\Deprecated', + 'similar' => 'VuFind\Related\Similar', + 'worldcateditions' => 'VuFind\Related\Deprecated', + 'worldcatsimilar' => 'VuFind\Related\WorldCatSimilar', + ]; + + /** + * Default plugin factories. + * + * @var array + */ + protected $factories = [ + 'VuFind\Related\Channels' => 'Zend\ServiceManager\Factory\InvokableFactory', + 'VuFind\Related\Deprecated' => + 'Zend\ServiceManager\Factory\InvokableFactory', + 'VuFind\Related\Similar' => 'VuFind\Related\SimilarFactory', + 'VuFind\Related\WorldCatSimilar' => 'VuFind\Related\SimilarFactory', + ]; + /** * Constructor * @@ -53,7 +79,7 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager // These objects are not meant to be shared -- every time we retrieve one, // we are building a brand new object. $this->sharedByDefault = false; - + $this->addAbstractFactory('VuFind\Related\PluginFactory'); parent::__construct($configOrContainerInstance, $v3config); } diff --git a/module/VuFind/src/VuFind/Related/SimilarFactory.php b/module/VuFind/src/VuFind/Related/SimilarFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..7ad77cd84b76e4850a0b988b2cc425976979aa44 --- /dev/null +++ b/module/VuFind/src/VuFind/Related/SimilarFactory.php @@ -0,0 +1,63 @@ +<?php +/** + * Factory for Similar related record module (and subclasses). + * + * 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 Related_Records + * @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\Related; + +use Interop\Container\ContainerInterface; +use Zend\ServiceManager\Factory\FactoryInterface; + +/** + * Factory for Similar related record module (and subclasses). + * + * @category VuFind + * @package Related_Records + * @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 SimilarFactory implements FactoryInterface +{ + /** + * 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 + ) { + return new $requestedName($container->get('VuFind\Search')); + } +}