diff --git a/module/VuFind/src/VuFind/Recommend/PluginManager.php b/module/VuFind/src/VuFind/Recommend/PluginManager.php index e340311211c8f9659a2c6f23587a13b6ff4737b7..320b00828c7dbd882032bf9d55e595d0906d1bd0 100644 --- a/module/VuFind/src/VuFind/Recommend/PluginManager.php +++ b/module/VuFind/src/VuFind/Recommend/PluginManager.php @@ -52,7 +52,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->setShareByDefault(false); + $this->sharedByDefault = false; parent::__construct($configOrContainerInstance, $v3config); } diff --git a/module/VuFind/src/VuFind/RecordDriver/PluginManager.php b/module/VuFind/src/VuFind/RecordDriver/PluginManager.php index e55ce0ab33d9e06691d99dec1b28235463b6eee0..1d5fe47316f1dc3db3596c11575916f73dd282da 100644 --- a/module/VuFind/src/VuFind/RecordDriver/PluginManager.php +++ b/module/VuFind/src/VuFind/RecordDriver/PluginManager.php @@ -52,17 +52,16 @@ 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->setShareByDefault(false); + $this->sharedByDefault = false; parent::__construct($configOrContainerInstance, $v3config); // Add an initializer for setting up hierarchies - $initializer = function ($instance, $manager) { + $initializer = function ($sm, $instance) { $hasHierarchyType = is_callable([$instance, 'getHierarchyType']); if ($hasHierarchyType && is_callable([$instance, 'setHierarchyDriverManager']) ) { - $sm = $manager->getServiceLocator(); if ($sm && $sm->has('VuFind\HierarchyDriverPluginManager')) { $instance->setHierarchyDriverManager( $sm->get('VuFind\HierarchyDriverPluginManager') diff --git a/module/VuFind/src/VuFind/Related/PluginManager.php b/module/VuFind/src/VuFind/Related/PluginManager.php index 03554270f98d0d02acc97ebc580c82a8c6ea3034..48be182c15666f574d20fd84bde3339381ddaf19 100644 --- a/module/VuFind/src/VuFind/Related/PluginManager.php +++ b/module/VuFind/src/VuFind/Related/PluginManager.php @@ -52,7 +52,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->setShareByDefault(false); + $this->sharedByDefault = false; parent::__construct($configOrContainerInstance, $v3config); } diff --git a/module/VuFind/src/VuFind/Search/Params/PluginManager.php b/module/VuFind/src/VuFind/Search/Params/PluginManager.php index 60664942f3f7c74b61c56d040f7d58786e66d228..ac9ab53e8d0e4fa3e44ec6c795f635df58da78ca 100644 --- a/module/VuFind/src/VuFind/Search/Params/PluginManager.php +++ b/module/VuFind/src/VuFind/Search/Params/PluginManager.php @@ -52,7 +52,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->setShareByDefault(false); + $this->sharedByDefault = false; parent::__construct($configOrContainerInstance, $v3config); } diff --git a/module/VuFind/src/VuFind/Search/Results/PluginManager.php b/module/VuFind/src/VuFind/Search/Results/PluginManager.php index 076f6ef5ec5527bfdcb634445c59cb2ce104db1a..435daa23976757e109cee2e15d75cf06aae7e55a 100644 --- a/module/VuFind/src/VuFind/Search/Results/PluginManager.php +++ b/module/VuFind/src/VuFind/Search/Results/PluginManager.php @@ -52,7 +52,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->setShareByDefault(false); + $this->sharedByDefault = false; parent::__construct($configOrContainerInstance, $v3config); } diff --git a/module/VuFind/src/VuFind/ServiceManager/AbstractPluginManager.php b/module/VuFind/src/VuFind/ServiceManager/AbstractPluginManager.php index 3cb098c047e21dcc6a75d8243b4abf785b60c064..64eb95114b9294241d9614f994f07c4a484c1ca2 100644 --- a/module/VuFind/src/VuFind/ServiceManager/AbstractPluginManager.php +++ b/module/VuFind/src/VuFind/ServiceManager/AbstractPluginManager.php @@ -28,7 +28,7 @@ namespace VuFind\ServiceManager; use Zend\ServiceManager\AbstractPluginManager as Base; -use Zend\ServiceManager\Exception\RuntimeException as ServiceManagerRuntimeException; +use Zend\ServiceManager\Exception\InvalidServiceException; /** * VuFind Plugin Manager @@ -43,6 +43,8 @@ use Zend\ServiceManager\Exception\RuntimeException as ServiceManagerRuntimeExcep */ abstract class AbstractPluginManager extends Base { + use LowerCaseServiceNameTrait; + /** * Constructor * @@ -69,14 +71,14 @@ abstract class AbstractPluginManager extends Base * * @param mixed $plugin Plugin to validate * - * @throws ServiceManagerRuntimeException if invalid + * @throws InvalidServiceException if invalid * @return void */ public function validate($plugin) { $expectedInterface = $this->getExpectedInterface(); if (!($plugin instanceof $expectedInterface)) { - throw new ServiceManagerRuntimeException( + throw new InvalidServiceException( 'Plugin ' . get_class($plugin) . ' does not belong to ' . $expectedInterface ); diff --git a/module/VuFind/src/VuFind/ServiceManager/LowerCaseServiceNameTrait.php b/module/VuFind/src/VuFind/ServiceManager/LowerCaseServiceNameTrait.php new file mode 100644 index 0000000000000000000000000000000000000000..35f2a2aaff4a58c1768a33678eeaaf6f9b2ea0fc --- /dev/null +++ b/module/VuFind/src/VuFind/ServiceManager/LowerCaseServiceNameTrait.php @@ -0,0 +1,87 @@ +<?php +/** + * Trait for plugin managers that allows service names to be normalized to lowercase + * (for backward compatibility with ServiceManager v2). + * + * PHP version 5 + * + * Copyright (C) Villanova University 2017. + * + * 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 ServiceManager + * @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\ServiceManager; + +/** + * Trait for plugin managers that allows service names to be normalized to lowercase + * (for backward compatibility with ServiceManager v2). + * + * @category VuFind + * @package ServiceManager + * @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 + */ +trait LowerCaseServiceNameTrait +{ + /** + * Retrieve a plugin + * + * @param string $name Name of plugin + * + * @return mixed + */ + public function get($name) + { + return parent::get($this->getNormalizedServiceName($name)); + } + + /** + * Returns true if the container can return an entry for the given identifier. + * Returns false otherwise. + * + * @param string $id Identifier of the entry to look for. + * + * @return bool + */ + public function has($id) + { + return parent::has($this->getNormalizedServiceName($id)); + } + + /** + * Hack for backward compatibility with services defined under + * ServiceManager v2, when service names were case-insensitive. + * TODO: set up aliases and/or normalize code to eliminate the need for this. + * + * @param string $name Service name + * + * @return string + */ + protected function getNormalizedServiceName($name) + { + if ($name != ($lower = strtolower($name)) + && (isset($this->services[$lower]) || isset($this->factories[$lower]) + || isset($this->aliases[$lower])) + ) { + return $lower; + } + return $name; + } +}