From 26ba9814c157e388902ffacd3b86049f3950d51a Mon Sep 17 00:00:00 2001 From: Demian Katz Date: Wed, 1 Nov 2017 16:03:38 -0400 Subject: [PATCH] Eliminate VuFindPluginInitializer. (#1069) - Implementing a setPluginManager method no longer triggers auto-injection. --- module/VuFind/config/module.config.php | 2 +- module/VuFind/src/VuFind/Auth/Factory.php | 18 +++++- .../ServiceManager/AbstractPluginManager.php | 2 +- .../VuFindPluginInitializer.php | 58 ------------------- .../src/VuFindTest/Auth/MultiAuthTest.php | 4 +- 5 files changed, 22 insertions(+), 62 deletions(-) delete mode 100644 module/VuFind/src/VuFind/ServiceManager/VuFindPluginInitializer.php diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index 7caf5bd9356..5996d830bd4 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -304,6 +304,7 @@ 'choiceauth' => 'VuFind\Auth\Factory::getChoiceAuth', 'facebook' => 'VuFind\Auth\Factory::getFacebook', 'ils' => 'VuFind\Auth\Factory::getILS', + 'multiauth' => 'VuFind\Auth\Factory::getMultiAuth', 'multiils' => 'VuFind\Auth\Factory::getMultiILS', 'shibboleth' => 'VuFind\Auth\Factory::getShibboleth' ], @@ -311,7 +312,6 @@ 'cas' => 'VuFind\Auth\CAS', 'database' => 'VuFind\Auth\Database', 'ldap' => 'VuFind\Auth\LDAP', - 'multiauth' => 'VuFind\Auth\MultiAuth', 'sip2' => 'VuFind\Auth\SIP2', ], 'aliases' => [ diff --git a/module/VuFind/src/VuFind/Auth/Factory.php b/module/VuFind/src/VuFind/Auth/Factory.php index 92146869562..c5bd771b479 100644 --- a/module/VuFind/src/VuFind/Auth/Factory.php +++ b/module/VuFind/src/VuFind/Auth/Factory.php @@ -54,7 +54,9 @@ public static function getChoiceAuth(ServiceManager $sm) $container = new \Zend\Session\Container( 'ChoiceAuth', $sm->getServiceLocator()->get('VuFind\SessionManager') ); - return new ChoiceAuth($container); + $auth = new ChoiceAuth($container); + $auth->setPluginManager($sm); + return $auth; } /** @@ -154,6 +156,20 @@ public static function getManager(ServiceManager $sm) return $manager; } + /** + * Construct the MultiAuth plugin. + * + * @param ServiceManager $sm Service manager. + * + * @return MultiAuth + */ + public static function getMultiAuth(ServiceManager $sm) + { + $auth = new MultiAuth(); + $auth->setPluginManager($sm); + return $auth; + } + /** * Construct the MultiILS plugin. * diff --git a/module/VuFind/src/VuFind/ServiceManager/AbstractPluginManager.php b/module/VuFind/src/VuFind/ServiceManager/AbstractPluginManager.php index f766a7d4574..e37b495a58b 100644 --- a/module/VuFind/src/VuFind/ServiceManager/AbstractPluginManager.php +++ b/module/VuFind/src/VuFind/ServiceManager/AbstractPluginManager.php @@ -57,7 +57,7 @@ public function __construct($configOrContainerInstance = null, ) { parent::__construct($configOrContainerInstance, $v3config); $this->addInitializer( - 'VuFind\ServiceManager\VuFindPluginInitializer', false + 'VuFind\ServiceManager\ZendPluginInitializer', false ); } diff --git a/module/VuFind/src/VuFind/ServiceManager/VuFindPluginInitializer.php b/module/VuFind/src/VuFind/ServiceManager/VuFindPluginInitializer.php deleted file mode 100644 index 3f02894dea0..00000000000 --- a/module/VuFind/src/VuFind/ServiceManager/VuFindPluginInitializer.php +++ /dev/null @@ -1,58 +0,0 @@ - - * @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 - * @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/tests/unit-tests/src/VuFindTest/Auth/MultiAuthTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/MultiAuthTest.php index 2f8ec411935..5b341197184 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/MultiAuthTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Auth/MultiAuthTest.php @@ -53,7 +53,9 @@ public function getAuthObject($config = null) if (null === $config) { $config = $this->getAuthConfig(); } - $obj = clone $this->getAuthManager()->get('MultiAuth'); + $manager = $this->getAuthManager(); + $obj = clone $manager->get('MultiAuth'); + $obj->setPluginManager($manager); $obj->setConfig($config); return $obj; }