From 10ac8b373d2b0e3a07b2bfcf0ab20485bbb3b69b Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Tue, 14 Feb 2017 14:45:45 -0500
Subject: [PATCH] Adjusted plugin managers to have explicitly-injected service
 locators. - Improves forward-compatibility with ZF3.

---
 .../src/VuFind/Recommend/PluginManager.php    | 19 +++++++++++--------
 .../src/VuFind/RecordDriver/PluginManager.php | 16 ++++++++++------
 .../src/VuFind/Related/PluginManager.php      | 19 +++++++++++--------
 .../Role/DynamicRoleProviderFactory.php       |  4 ++--
 .../VuFind/Search/Params/PluginManager.php    | 14 +++++++++-----
 .../VuFind/Search/Results/PluginManager.php   | 14 +++++++++-----
 module/VuFind/src/VuFind/Service/Factory.php  |  4 +---
 .../ServiceManager/AbstractPluginManager.php  | 13 ++++++++-----
 8 files changed, 61 insertions(+), 42 deletions(-)

diff --git a/module/VuFind/src/VuFind/Recommend/PluginManager.php b/module/VuFind/src/VuFind/Recommend/PluginManager.php
index 4a1270d2949..e340311211c 100644
--- a/module/VuFind/src/VuFind/Recommend/PluginManager.php
+++ b/module/VuFind/src/VuFind/Recommend/PluginManager.php
@@ -26,7 +26,6 @@
  * @link     https://vufind.org/wiki/development:plugins:recommendation_modules Wiki
  */
 namespace VuFind\Recommend;
-use Zend\ServiceManager\ConfigInterface;
 
 /**
  * Recommendation module plugin manager
@@ -42,16 +41,20 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
     /**
      * Constructor
      *
-     * @param ConfigInterface $configuration Configuration settings (optional)
+     * Make sure plugins are properly initialized.
+     *
+     * @param mixed $configOrContainerInstance Configuration or container instance
+     * @param array $v3config                  If $configOrContainerInstance is a
+     * container, this value will be passed to the parent constructor.
      */
-    public function __construct(ConfigInterface $configuration = null)
-    {
-        // These plugins are not meant to be shared -- the same module may be used
-        // multiple times with different configurations, so we need to build a new
-        // copy each time the plugin is retrieved.
+    public function __construct($configOrContainerInstance = null,
+        array $v3config = []
+    ) {
+        // These objects are not meant to be shared -- every time we retrieve one,
+        // we are building a brand new object.
         $this->setShareByDefault(false);
 
-        parent::__construct($configuration);
+        parent::__construct($configOrContainerInstance, $v3config);
     }
 
     /**
diff --git a/module/VuFind/src/VuFind/RecordDriver/PluginManager.php b/module/VuFind/src/VuFind/RecordDriver/PluginManager.php
index 31a36761fda..e55ce0ab33d 100644
--- a/module/VuFind/src/VuFind/RecordDriver/PluginManager.php
+++ b/module/VuFind/src/VuFind/RecordDriver/PluginManager.php
@@ -26,7 +26,6 @@
  * @link     https://vufind.org/wiki/development:plugins:record_drivers Wiki
  */
 namespace VuFind\RecordDriver;
-use Zend\ServiceManager\ConfigInterface;
 
 /**
  * Record driver plugin manager
@@ -42,15 +41,20 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
     /**
      * Constructor
      *
-     * @param ConfigInterface $configuration Configuration settings (optional)
+     * Make sure plugins are properly initialized.
+     *
+     * @param mixed $configOrContainerInstance Configuration or container instance
+     * @param array $v3config                  If $configOrContainerInstance is a
+     * container, this value will be passed to the parent constructor.
      */
-    public function __construct(ConfigInterface $configuration = null)
-    {
-        // Record drivers are not meant to be shared -- every time we retrieve one,
+    public function __construct($configOrContainerInstance = null,
+        array $v3config = []
+    ) {
+        // These objects are not meant to be shared -- every time we retrieve one,
         // we are building a brand new object.
         $this->setShareByDefault(false);
 
-        parent::__construct($configuration);
+        parent::__construct($configOrContainerInstance, $v3config);
 
         // Add an initializer for setting up hierarchies
         $initializer = function ($instance, $manager) {
diff --git a/module/VuFind/src/VuFind/Related/PluginManager.php b/module/VuFind/src/VuFind/Related/PluginManager.php
index f57d380fabd..03554270f98 100644
--- a/module/VuFind/src/VuFind/Related/PluginManager.php
+++ b/module/VuFind/src/VuFind/Related/PluginManager.php
@@ -26,7 +26,6 @@
  * @link     https://vufind.org/wiki/development:plugins:related_records_modules Wiki
  */
 namespace VuFind\Related;
-use Zend\ServiceManager\ConfigInterface;
 
 /**
  * Related record plugin manager
@@ -42,16 +41,20 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
     /**
      * Constructor
      *
-     * @param ConfigInterface $configuration Configuration settings (optional)
+     * Make sure plugins are properly initialized.
+     *
+     * @param mixed $configOrContainerInstance Configuration or container instance
+     * @param array $v3config                  If $configOrContainerInstance is a
+     * container, this value will be passed to the parent constructor.
      */
-    public function __construct(ConfigInterface $configuration = null)
-    {
-        // These plugins are not meant to be shared -- the same module may be used
-        // multiple times with different configurations, so we need to build a new
-        // copy each time the plugin is retrieved.
+    public function __construct($configOrContainerInstance = null,
+        array $v3config = []
+    ) {
+        // These objects are not meant to be shared -- every time we retrieve one,
+        // we are building a brand new object.
         $this->setShareByDefault(false);
 
-        parent::__construct($configuration);
+        parent::__construct($configOrContainerInstance, $v3config);
     }
 
     /**
diff --git a/module/VuFind/src/VuFind/Role/DynamicRoleProviderFactory.php b/module/VuFind/src/VuFind/Role/DynamicRoleProviderFactory.php
index 7f03083eac5..9fdc312f200 100644
--- a/module/VuFind/src/VuFind/Role/DynamicRoleProviderFactory.php
+++ b/module/VuFind/src/VuFind/Role/DynamicRoleProviderFactory.php
@@ -70,9 +70,9 @@ class DynamicRoleProviderFactory implements FactoryInterface
         ServiceLocatorInterface $serviceLocator, array $rbacConfig
     ) {
         $pm = new PermissionProvider\PluginManager(
-            new Config($rbacConfig['vufind_permission_provider_manager'])
+            $serviceLocator->getServiceLocator(),
+            $rbacConfig['vufind_permission_provider_manager']
         );
-        $pm->setServiceLocator($serviceLocator->getServiceLocator());
         return $pm;
     }
 
diff --git a/module/VuFind/src/VuFind/Search/Params/PluginManager.php b/module/VuFind/src/VuFind/Search/Params/PluginManager.php
index fcace47adef..60664942f3f 100644
--- a/module/VuFind/src/VuFind/Search/Params/PluginManager.php
+++ b/module/VuFind/src/VuFind/Search/Params/PluginManager.php
@@ -26,7 +26,6 @@
  * @link     https://vufind.org/wiki/development:plugins:record_drivers Wiki
  */
 namespace VuFind\Search\Params;
-use Zend\ServiceManager\ConfigInterface;
 
 /**
  * Search params plugin manager
@@ -42,15 +41,20 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
     /**
      * Constructor
      *
-     * @param ConfigInterface $configuration Configuration settings (optional)
+     * Make sure plugins are properly initialized.
+     *
+     * @param mixed $configOrContainerInstance Configuration or container instance
+     * @param array $v3config                  If $configOrContainerInstance is a
+     * container, this value will be passed to the parent constructor.
      */
-    public function __construct(ConfigInterface $configuration = null)
-    {
+    public function __construct($configOrContainerInstance = null,
+        array $v3config = []
+    ) {
         // These objects are not meant to be shared -- every time we retrieve one,
         // we are building a brand new object.
         $this->setShareByDefault(false);
 
-        parent::__construct($configuration);
+        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 2341fef78c4..076f6ef5ec5 100644
--- a/module/VuFind/src/VuFind/Search/Results/PluginManager.php
+++ b/module/VuFind/src/VuFind/Search/Results/PluginManager.php
@@ -26,7 +26,6 @@
  * @link     https://vufind.org/wiki/development:plugins:record_drivers Wiki
  */
 namespace VuFind\Search\Results;
-use Zend\ServiceManager\ConfigInterface;
 
 /**
  * Search results plugin manager
@@ -42,15 +41,20 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
     /**
      * Constructor
      *
-     * @param ConfigInterface $configuration Configuration settings (optional)
+     * Make sure plugins are properly initialized.
+     *
+     * @param mixed $configOrContainerInstance Configuration or container instance
+     * @param array $v3config                  If $configOrContainerInstance is a
+     * container, this value will be passed to the parent constructor.
      */
-    public function __construct(ConfigInterface $configuration = null)
-    {
+    public function __construct($configOrContainerInstance = null,
+        array $v3config = []
+    ) {
         // These objects are not meant to be shared -- every time we retrieve one,
         // we are building a brand new object.
         $this->setShareByDefault(false);
 
-        parent::__construct($configuration);
+        parent::__construct($configOrContainerInstance, $v3config);
     }
 
     /**
diff --git a/module/VuFind/src/VuFind/Service/Factory.php b/module/VuFind/src/VuFind/Service/Factory.php
index 8bb152163cd..57c97b52954 100644
--- a/module/VuFind/src/VuFind/Service/Factory.php
+++ b/module/VuFind/src/VuFind/Service/Factory.php
@@ -318,9 +318,7 @@ class Factory
         $configKey = strtolower(str_replace('\\', '_', $ns));
         $config = $sm->get('Config');
         return new $className(
-            new \Zend\ServiceManager\Config(
-                $config['vufind']['plugin_managers'][$configKey]
-            )
+            $sm, $config['vufind']['plugin_managers'][$configKey]
         );
     }
 
diff --git a/module/VuFind/src/VuFind/ServiceManager/AbstractPluginManager.php b/module/VuFind/src/VuFind/ServiceManager/AbstractPluginManager.php
index 94dc060fa38..6e83f1039bc 100644
--- a/module/VuFind/src/VuFind/ServiceManager/AbstractPluginManager.php
+++ b/module/VuFind/src/VuFind/ServiceManager/AbstractPluginManager.php
@@ -46,13 +46,16 @@ abstract class AbstractPluginManager extends Base
     /**
      * Constructor
      *
-     * Make sure table gateways are properly initialized.
+     * Make sure plugins are properly initialized.
      *
-     * @param ConfigInterface $configuration Configuration settings (optional)
+     * @param mixed $configOrContainerInstance Configuration or container instance
+     * @param array $v3config                  If $configOrContainerInstance is a
+     * container, this value will be passed to the parent constructor.
      */
-    public function __construct(ConfigInterface $configuration = null)
-    {
-        parent::__construct($configuration);
+    public function __construct($configOrContainerInstance = null,
+        array $v3config = []
+    ) {
+        parent::__construct($configOrContainerInstance, $v3config);
         $this->addInitializer(
             ['VuFind\ServiceManager\Initializer', 'initPlugin'], false
         );
-- 
GitLab