From dc283573797facded78369189bb5d39310be9622 Mon Sep 17 00:00:00 2001 From: Dorian Merz <merz@ub.uni-leipzig.de> Date: Tue, 7 Jul 2020 14:37:10 +0200 Subject: [PATCH] refs #17914 [master] fix staticStatusRules configuration * add via Delegator * validate config file before adding * make factory more generic ** allows inherited FincLibero drivers to use same factory method --- module/finc/config/module.config.php | 5 ++ module/finc/src/finc/ILS/Driver/Factory.php | 17 ++-- .../StaticStatusRulesDelegatorFactory.php | 80 +++++++++++++++++++ 3 files changed, 95 insertions(+), 7 deletions(-) create mode 100644 module/finc/src/finc/ILS/Driver/StaticStatusRulesDelegatorFactory.php diff --git a/module/finc/config/module.config.php b/module/finc/config/module.config.php index e4c87f8747a..ecf42016f54 100644 --- a/module/finc/config/module.config.php +++ b/module/finc/config/module.config.php @@ -88,6 +88,11 @@ $config = [ 'finctheca' => 'finc\ILS\Driver\FincTheca', 'finclibero' => 'finc\ILS\Driver\FincLibero' ], + 'delegators' => [ + 'finc\ILS\Driver\FincLibero' => [ + 'finc\ILS\Driver\StaticStatusRulesDelegatorFactory' + ] + ] ], 'recommend' => [ 'factories' => [ diff --git a/module/finc/src/finc/ILS/Driver/Factory.php b/module/finc/src/finc/ILS/Driver/Factory.php index 56c3a0e7806..dc4f25edffe 100644 --- a/module/finc/src/finc/ILS/Driver/Factory.php +++ b/module/finc/src/finc/ILS/Driver/Factory.php @@ -137,12 +137,16 @@ class Factory /** * Factory for FincLibero driver. * - * @param \Psr\Container\ContainerInterface $container Service manager. + * @param ContainerInterface $container Service manager + * @param string $requestedName Service being created + * @param null|array $options Extra options (optional) + * + * @return object * - * @return FincLibero */ - public static function getFincLibero(ContainerInterface $container) - { + public static function getFincLibero(ContainerInterface $container, $requestedName, + array $options = null + ) { $factory = new \ProxyManager\Factory\LazyLoadingValueHolderFactory($container->get('VuFind\ProxyConfig')); $callback = function (& $wrapped, $proxy) use ($container) { @@ -151,7 +155,7 @@ class Factory $proxy->setProxyInitializer(null); }; - $fl = new FincLibero( + $fl = new $requestedName( $container->get('VuFind\DateConverter'), $container->get('VuFind\SessionManager'), $container->get('VuFind\RecordLoader'), @@ -164,8 +168,7 @@ class Factory $container->get('VuFind\CacheManager')->getCache('object') ); - $fl->staticStatusRules = $container->get('VuFind\YamlReader')->get('StaticStatusRules.yaml'); - return $fl; } + } diff --git a/module/finc/src/finc/ILS/Driver/StaticStatusRulesDelegatorFactory.php b/module/finc/src/finc/ILS/Driver/StaticStatusRulesDelegatorFactory.php new file mode 100644 index 00000000000..ffc988c2d4f --- /dev/null +++ b/module/finc/src/finc/ILS/Driver/StaticStatusRulesDelegatorFactory.php @@ -0,0 +1,80 @@ +<?php +/** + * Munger Injection Factory + * + * A Delegator Factory that registers several listeners at events triggered by the + * VuFind\Search service. + * + * PHP version 7 + * + * Copyright (C) Leipzig University Library 2019. + * + * 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 Finc/Service + * @author Dorian Merz <merz@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org Main Page + */ +namespace finc\ILS\Driver; + +use Interop\Container\ContainerInterface; +use VuFindSearch\Query\Query; +use VuFindSearch\Query\QueryGroup; +use VuFindSearch\Service as SearchService; +use Zend\Config\Config; +use Zend\EventManager\EventInterface; +use Zend\ServiceManager\Factory\DelegatorFactoryInterface; + +/** + * Munger Injection Factory + * + * + * @category VuFind + * @package Finc/ILS + * @author Dorian Merz <merz@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org Main Page + */ +class StaticStatusRulesDelegatorFactory implements DelegatorFactoryInterface +{ + /** + * Adds staticStatusRules if there is a valid StaticStatusRules.json available + * + * @param ContainerInterface $container + * @param string $name + * @param callable $callback + * @param array|null $options + * + * @return mixed + */ + public function __invoke( + ContainerInterface $container, + $name, + callable $callback, + array $options = null + ) { + $instance = call_user_func($callback); + + $staticStatusRules = $container->get('VuFind\YamlReader')->get('StaticStatusRules.yaml'); + if (!empty($staticStatusRules)) { + if (isset($staticStatusRules['rules']) && isset($staticStatusRules['stopFlags'])) { + $instance->staticStatusRules = $staticStatusRules; + } + } + + return $instance; + } +} -- GitLab