diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index 3fb4db62d2bc79e13b2d64090ac9219370baca65..7caf5bd9356635221f50ae4c68b1df9340ae7b1b 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -249,7 +249,7 @@ $config = [ 'VuFind\Session\Settings' => 'VuFind\Session\Settings', ], 'initializers' => [ - 'VuFind\ServiceManager\Initializer::initInstance', + 'VuFind\ServiceManager\ServiceInitializer', ], 'aliases' => [ 'mvctranslator' => 'VuFind\Translator', @@ -259,7 +259,7 @@ $config = [ 'translator' => [], 'view_helpers' => [ 'initializers' => [ - 'VuFind\ServiceManager\Initializer::initZendPlugin', + 'VuFind\ServiceManager\ZendPluginInitializer', ], ], 'view_manager' => [ diff --git a/module/VuFind/src/VuFind/Controller/CoverController.php b/module/VuFind/src/VuFind/Controller/CoverController.php index 8e62c53bfe0d3fb10e39cec7f9beb21b510ff538..f71d0ce3072d64a71c5b8c510f7c338376917cf3 100644 --- a/module/VuFind/src/VuFind/Controller/CoverController.php +++ b/module/VuFind/src/VuFind/Controller/CoverController.php @@ -83,9 +83,8 @@ class CoverController extends AbstractBase $this->serviceLocator->get('VuFind\Http')->createClient(), $cacheDir ); - \VuFind\ServiceManager\Initializer::initInstance( - $this->loader, $this->serviceLocator - ); + $initializer = new \VuFind\ServiceManager\ServiceInitializer(); + $initializer->initialize($this->loader, $this->serviceLocator); } return $this->loader; } diff --git a/module/VuFind/src/VuFind/Controller/QRCodeController.php b/module/VuFind/src/VuFind/Controller/QRCodeController.php index 6937ff1151d070ef8218d5312467d5d12c83cfc9..d5e286e496f669b426bc1a9a6b00eaafb7606c20 100644 --- a/module/VuFind/src/VuFind/Controller/QRCodeController.php +++ b/module/VuFind/src/VuFind/Controller/QRCodeController.php @@ -62,9 +62,8 @@ class QRCodeController extends AbstractBase $this->getConfig(), $this->serviceLocator->get('VuFindTheme\ThemeInfo') ); - \VuFind\ServiceManager\Initializer::initInstance( - $this->loader, $this->serviceLocator - ); + $initializer = new \VuFind\ServiceManager\ServiceInitializer(); + $initializer->initialize($this->loader, $this->serviceLocator); } return $this->loader; } diff --git a/module/VuFind/src/VuFind/ServiceManager/AbstractPluginManager.php b/module/VuFind/src/VuFind/ServiceManager/AbstractPluginManager.php index de6dbe75522b751b2066fb48b16afddb0aa0ccc2..f766a7d4574e183060f149a7b809705a3cafac02 100644 --- a/module/VuFind/src/VuFind/ServiceManager/AbstractPluginManager.php +++ b/module/VuFind/src/VuFind/ServiceManager/AbstractPluginManager.php @@ -57,7 +57,7 @@ abstract class AbstractPluginManager extends Base ) { parent::__construct($configOrContainerInstance, $v3config); $this->addInitializer( - ['VuFind\ServiceManager\Initializer', 'initPlugin'], false + 'VuFind\ServiceManager\VuFindPluginInitializer', false ); } diff --git a/module/VuFind/src/VuFind/ServiceManager/Initializer.php b/module/VuFind/src/VuFind/ServiceManager/ServiceInitializer.php similarity index 67% rename from module/VuFind/src/VuFind/ServiceManager/Initializer.php rename to module/VuFind/src/VuFind/ServiceManager/ServiceInitializer.php index 1872c148fdd6f28bb256765574dd0a52514a6f1a..11cf43e73a07d33527400a365f51f7233ed60c5c 100644 --- a/module/VuFind/src/VuFind/ServiceManager/Initializer.php +++ b/module/VuFind/src/VuFind/ServiceManager/ServiceInitializer.php @@ -27,7 +27,7 @@ */ namespace VuFind\ServiceManager; -use Zend\ServiceManager\ServiceManager; +use Zend\ServiceManager\ServiceLocatorInterface; /** * VuFind Service Initializer @@ -38,16 +38,16 @@ use Zend\ServiceManager\ServiceManager; * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link https://vufind.org/wiki/development Wiki */ -class Initializer +class ServiceInitializer implements \Zend\ServiceManager\InitializerInterface { /** * Check if the record cache is enabled within a service manager. * - * @param ServiceManager $sm Service manager + * @param ServiceLocatorInterface $sm Service manager * * @return bool */ - protected static function isCacheEnabled(ServiceManager $sm) + protected function isCacheEnabled(ServiceLocatorInterface $sm) { // Use static cache to save time on repeated lookups: static $enabled = null; @@ -72,12 +72,12 @@ class Initializer /** * Given an instance and a Service Manager, initialize the instance. * - * @param object $instance Instance to initialize - * @param ServiceManager $sm Service manager + * @param object $instance Instance to initialize + * @param ServiceLocatorInterface $sm Service manager * * @return object */ - public static function initInstance($instance, ServiceManager $sm) + public function initialize($instance, ServiceLocatorInterface $sm) { if ($instance instanceof \VuFind\Db\Table\DbTableAwareInterface) { $instance->setDbTableManager($sm->get('VuFind\DbTablePluginManager')); @@ -93,46 +93,10 @@ class Initializer } // Only inject cache if configuration enabled (to save resources): if ($instance instanceof \VuFind\Record\Cache\RecordCacheAwareInterface - && static::isCacheEnabled($sm) + && $this->isCacheEnabled($sm) ) { $instance->setRecordCache($sm->get('VuFind\RecordCache')); } return $instance; } - - /** - * Given a Zend Framework Plugin Manager, initialize the instance. - * - * @param object $instance Instance to - * initialize - * @param \Zend\ServiceManager\AbstractPluginManager $manager Plugin manager - * - * @return object - */ - public static function initZendPlugin($instance, - \Zend\ServiceManager\AbstractPluginManager $manager - ) { - $sm = $manager->getServiceLocator(); - if (null !== $sm) { - static::initInstance($instance, $sm); - } - return $instance; - } - - /** - * Given an instance and a Plugin Manager, initialize the instance. - * - * @param object $instance Instance to initialize - * @param AbstractPluginManager $manager Plugin manager - * - * @return object - */ - public static function initPlugin($instance, AbstractPluginManager $manager) - { - static::initZendPlugin($instance, $manager); - if (method_exists($instance, 'setPluginManager')) { - $instance->setPluginManager($manager); - } - return $instance; - } } diff --git a/module/VuFind/src/VuFind/ServiceManager/VuFindPluginInitializer.php b/module/VuFind/src/VuFind/ServiceManager/VuFindPluginInitializer.php new file mode 100644 index 0000000000000000000000000000000000000000..3f02894dea077f5b5230ffb38871056354f7787b --- /dev/null +++ b/module/VuFind/src/VuFind/ServiceManager/VuFindPluginInitializer.php @@ -0,0 +1,58 @@ +<?php +/** + * VuFind Plugin Initializer + * + * PHP version 5 + * + * Copyright (C) Villanova University 2010. + * + * 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; + +use Zend\ServiceManager\ServiceLocatorInterface; + +/** + * VuFind Plugin Initializer + * + * @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 + */ +class VuFindPluginInitializer extends ZendPluginInitializer +{ + /** + * Given an instance and a Plugin Manager, initialize the instance. + * + * @param object $instance Instance to initialize + * @param ServiceLocatorInterface $manager Plugin manager + * + * @return object + */ + public function initialize($instance, ServiceLocatorInterface $manager) + { + if (method_exists($instance, 'setPluginManager')) { + $instance->setPluginManager($manager); + } + return parent::initialize($instance, $manager); + } +} diff --git a/module/VuFind/src/VuFind/ServiceManager/ZendPluginInitializer.php b/module/VuFind/src/VuFind/ServiceManager/ZendPluginInitializer.php new file mode 100644 index 0000000000000000000000000000000000000000..17896becc23f87be1ca46c16e20a7f75be33f6e3 --- /dev/null +++ b/module/VuFind/src/VuFind/ServiceManager/ZendPluginInitializer.php @@ -0,0 +1,57 @@ +<?php +/** + * Zend Framework Plugin Initializer + * + * PHP version 5 + * + * Copyright (C) Villanova University 2010. + * + * 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; + +use Zend\ServiceManager\ServiceLocatorInterface; + +/** + * Zend Framework Plugin Initializer + * + * @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 + */ +class ZendPluginInitializer extends ServiceInitializer +{ + /** + * Given an instance and a Plugin Manager, initialize the instance. + * + * @param object $instance Instance to initialize + * @param ServiceLocatorInterface $manager Plugin manager + * + * @return object + */ + public function initialize($instance, ServiceLocatorInterface $manager) + { + $sm = $manager->getServiceLocator(); + return (null !== $sm) + ? parent::initialize($instance, $sm) : $instance; + } +} diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Auth/ShibbolethTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Auth/ShibbolethTest.php index e08fb39ef404e9a25318384405ead3ba77fa7cbb..4387bef40d2499a426c778f5d6ba1e78b5c374ed 100644 --- a/module/VuFind/tests/integration-tests/src/VuFindTest/Auth/ShibbolethTest.php +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Auth/ShibbolethTest.php @@ -80,9 +80,8 @@ class ShibbolethTest extends \VuFindTest\Unit\DbTestCase $config = $this->getAuthConfig(); } $obj = new Shibboleth($this->createMock('Zend\Session\ManagerInterface')); - \VuFind\ServiceManager\Initializer::initInstance( - $obj, $this->getServiceManager() - ); + $initializer = new \VuFind\ServiceManager\ServiceInitializer(); + $initializer->initialize($obj, $this->getServiceManager()); $obj->setConfig($config); return $obj; }