From 10ce4b8c4800e53c99ba4a051b2c8ae5cdc4e845 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Thu, 25 Apr 2013 13:17:00 -0400
Subject: [PATCH] Eliminated need for Params init() method by passing config
 reader to constructor.

---
 module/VuFind/src/VuFind/Search/Base/Params.php   | 15 +++------------
 .../VuFind/src/VuFind/Search/Favorites/Params.php |  8 ++++----
 .../src/VuFind/Search/Params/PluginFactory.php    |  9 ++++-----
 module/VuFind/src/VuFind/Search/Solr/Params.php   | 12 ++++++------
 4 files changed, 17 insertions(+), 27 deletions(-)

diff --git a/module/VuFind/src/VuFind/Search/Base/Params.php b/module/VuFind/src/VuFind/Search/Base/Params.php
index 22673a553ba..25a3294848b 100644
--- a/module/VuFind/src/VuFind/Search/Base/Params.php
+++ b/module/VuFind/src/VuFind/Search/Base/Params.php
@@ -89,9 +89,10 @@ class Params implements ServiceLocatorAwareInterface
     /**
      * Constructor
      *
-     * @param \VuFind\Search\Base\Options $options Options to use
+     * @param \VuFind\Search\Base\Options  $options      Options to use
+     * @param \VuFind\Config\PluginManager $configLoader Config loader
      */
-    public function __construct($options)
+    public function __construct($options, \VuFind\Config\PluginManager $configLoader)
     {
         $this->setOptions($options);
 
@@ -99,16 +100,6 @@ class Params implements ServiceLocatorAwareInterface
         $this->query = new Query();
     }
 
-    /**
-     * Perform initialization that cannot occur in constructor due to need for
-     * injected dependencies.
-     *
-     * @return void
-     */
-    public function init()
-    {
-    }
-
     /**
      * Get the search options object.
      *
diff --git a/module/VuFind/src/VuFind/Search/Favorites/Params.php b/module/VuFind/src/VuFind/Search/Favorites/Params.php
index d7548db7ab0..a6e6a429dca 100644
--- a/module/VuFind/src/VuFind/Search/Favorites/Params.php
+++ b/module/VuFind/src/VuFind/Search/Favorites/Params.php
@@ -48,12 +48,12 @@ class Params extends \VuFind\Search\Base\Params
     /**
      * Constructor
      *
-     * @param \VuFind\Search\Base\Options $options Options to use (null to load
-     * defaults)
+     * @param \VuFind\Search\Base\Options  $options      Options to use
+     * @param \VuFind\Config\PluginManager $configLoader Config loader
      */
-    public function __construct($options = null)
+    public function __construct($options, \VuFind\Config\PluginManager $configLoader)
     {
-        parent::__construct($options);
+        parent::__construct($options, $configLoader);
         $this->recommendationsEnabled(true);
     }
 
diff --git a/module/VuFind/src/VuFind/Search/Params/PluginFactory.php b/module/VuFind/src/VuFind/Search/Params/PluginFactory.php
index 4680af41c06..c7361ea19b0 100644
--- a/module/VuFind/src/VuFind/Search/Params/PluginFactory.php
+++ b/module/VuFind/src/VuFind/Search/Params/PluginFactory.php
@@ -64,10 +64,9 @@ class PluginFactory extends \VuFind\ServiceManager\AbstractPluginFactory
             ->get('VuFind\SearchOptionsPluginManager')->get($requestedName);
         $class = $this->getClassName($name, $requestedName);
         // Clone the options instance in case caller modifies it:
-        $obj = new $class(clone($options));
-        // TODO: eliminate init method to get rid of this awkwardness:
-        $obj->setServiceLocator($serviceLocator->getServiceLocator());
-        $obj->init();
-        return $obj;
+        return new $class(
+            clone($options),
+            $serviceLocator->getServiceLocator()->get('VuFind\Config')
+        );
     }
 }
\ No newline at end of file
diff --git a/module/VuFind/src/VuFind/Search/Solr/Params.php b/module/VuFind/src/VuFind/Search/Solr/Params.php
index bc939d534ac..e1935653e84 100644
--- a/module/VuFind/src/VuFind/Search/Solr/Params.php
+++ b/module/VuFind/src/VuFind/Search/Solr/Params.php
@@ -67,17 +67,17 @@ class Params extends \VuFind\Search\Base\Params
     protected $facetSort = null;
 
     /**
-     * Perform initialization that cannot occur in constructor due to need for
-     * injected dependencies.
+     * Constructor
      *
-     * @return void
+     * @param \VuFind\Search\Base\Options  $options      Options to use
+     * @param \VuFind\Config\PluginManager $configLoader Config loader
      */
-    public function init()
+    public function __construct($options, \VuFind\Config\PluginManager $configLoader)
     {
-        parent::init();
+        parent::__construct($options, $configLoader);
 
         // Use basic facet limit by default, if set:
-        $config = $this->getServiceLocator()->get('VuFind\Config')->get('facets');
+        $config = $configLoader->get('facets');
         if (isset($config->Results_Settings->facet_limit)
             && is_numeric($config->Results_Settings->facet_limit)
         ) {
-- 
GitLab