From ca30902efa18360bf2d34e0baf79b6279f631877 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Fri, 6 Feb 2015 11:47:51 -0500
Subject: [PATCH] Take advantage of ServiceLocatorAwareTrait.

---
 .../Db/Row/ServiceLocatorAwareGateway.php     | 30 +----------------
 module/VuFind/src/VuFind/Db/Table/Gateway.php | 32 ++-----------------
 .../src/VuFind/ILS/Driver/MultiBackend.php    | 30 +----------------
 .../VuFind/src/VuFind/ILS/Driver/Symphony.php | 32 ++-----------------
 module/VuFind/src/VuFind/Log/Logger.php       | 32 ++-----------------
 .../VuFind/src/VuFind/Search/Base/Params.php  | 24 +++-----------
 .../VuFind/src/VuFind/Search/Base/Results.php | 24 +++-----------
 module/VuFind/src/VuFind/XSLT/Importer.php    | 30 +----------------
 8 files changed, 19 insertions(+), 215 deletions(-)

diff --git a/module/VuFind/src/VuFind/Db/Row/ServiceLocatorAwareGateway.php b/module/VuFind/src/VuFind/Db/Row/ServiceLocatorAwareGateway.php
index 019fb1b6ad4..99d40adbc44 100644
--- a/module/VuFind/src/VuFind/Db/Row/ServiceLocatorAwareGateway.php
+++ b/module/VuFind/src/VuFind/Db/Row/ServiceLocatorAwareGateway.php
@@ -41,12 +41,7 @@ use Zend\ServiceManager\ServiceLocatorAwareInterface,
 class ServiceLocatorAwareGateway extends RowGateway
     implements ServiceLocatorAwareInterface
 {
-    /**
-     * Service locator
-     *
-     * @var ServiceLocatorInterface
-     */
-    protected $serviceLocator;
+    use \Zend\ServiceManager\ServiceLocatorAwareTrait;
 
     /**
      * Get access to another table.
@@ -59,27 +54,4 @@ class ServiceLocatorAwareGateway extends RowGateway
     {
         return $this->getServiceLocator()->get($table);
     }
-
-    /**
-     * Set the service locator.
-     *
-     * @param ServiceLocatorInterface $serviceLocator Locator to register
-     *
-     * @return ServiceLocatorAwareGateway
-     */
-    public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
-    {
-        $this->serviceLocator = $serviceLocator;
-        return $this;
-    }
-
-    /**
-     * Get the service locator.
-     *
-     * @return \Zend\ServiceManager\ServiceLocatorInterface
-     */
-    public function getServiceLocator()
-    {
-        return $this->serviceLocator;
-    }
 }
diff --git a/module/VuFind/src/VuFind/Db/Table/Gateway.php b/module/VuFind/src/VuFind/Db/Table/Gateway.php
index 5b0c481ffc7..d1d314c0658 100644
--- a/module/VuFind/src/VuFind/Db/Table/Gateway.php
+++ b/module/VuFind/src/VuFind/Db/Table/Gateway.php
@@ -42,6 +42,8 @@ use Zend\Db\TableGateway\AbstractTableGateway,
  */
 class Gateway extends AbstractTableGateway implements ServiceLocatorAwareInterface
 {
+    use \Zend\ServiceManager\ServiceLocatorAwareTrait;
+
     /**
      * Name of class used to represent rows (null for default)
      *
@@ -49,13 +51,6 @@ class Gateway extends AbstractTableGateway implements ServiceLocatorAwareInterfa
      */
     protected $rowClass = null;
     
-    /**
-     * Service locator
-     *
-     * @var ServiceLocatorInterface
-     */
-    protected $serviceLocator;
-
     /**
      * Constructor
      *
@@ -160,27 +155,4 @@ class Gateway extends AbstractTableGateway implements ServiceLocatorAwareInterfa
     {
         return $this->getServiceLocator()->get($table);
     }
-
-    /**
-     * Set the service locator.
-     *
-     * @param ServiceLocatorInterface $serviceLocator Locator to register
-     *
-     * @return Gateway
-     */
-    public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
-    {
-        $this->serviceLocator = $serviceLocator;
-        return $this;
-    }
-
-    /**
-     * Get the service locator.
-     *
-     * @return \Zend\ServiceManager\ServiceLocatorInterface
-     */
-    public function getServiceLocator()
-    {
-        return $this->serviceLocator;
-    }
 }
diff --git a/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php b/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php
index 91cf00ebe76..c58948ca520 100644
--- a/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php
+++ b/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php
@@ -48,12 +48,7 @@ use VuFind\Exception\ILS as ILSException,
 class MultiBackend extends AbstractBase
     implements ServiceLocatorAwareInterface, \Zend\Log\LoggerAwareInterface
 {
-    /**
-     * The serviceLocator instance (implementing ServiceLocatorAwareInterface).
-     *
-     * @var object
-     */
-    protected $serviceLocator;
+    use \Zend\ServiceManager\ServiceLocatorAwareTrait;
 
     /**
      * The array of configured driver names.
@@ -179,29 +174,6 @@ class MultiBackend extends AbstractBase
             : '.';
     }
 
-    /**
-     * Set the service locator.
-     *
-     * @param ServiceLocatorInterface $serviceLocator Locator to register
-     *
-     * @return Manager
-     */
-    public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
-    {
-        $this->serviceLocator = $serviceLocator;
-        return $this;
-    }
-
-    /**
-     * Get the service locator.
-     *
-     * @return \Zend\ServiceManager\ServiceLocatorInterface
-     */
-    public function getServiceLocator()
-    {
-        return $this->serviceLocator;
-    }
-
     /**
      * Get Status
      *
diff --git a/module/VuFind/src/VuFind/ILS/Driver/Symphony.php b/module/VuFind/src/VuFind/ILS/Driver/Symphony.php
index 7e3e58393ef..c49cae17bc9 100644
--- a/module/VuFind/src/VuFind/ILS/Driver/Symphony.php
+++ b/module/VuFind/src/VuFind/ILS/Driver/Symphony.php
@@ -46,6 +46,8 @@ use Zend\Log\LoggerInterface, Zend\Log\LoggerAwareInterface;
 class Symphony extends AbstractBase
     implements ServiceLocatorAwareInterface, LoggerAwareInterface
 {
+    use \Zend\ServiceManager\ServiceLocatorAwareTrait;
+
     /**
      * Cache for policy information
      *
@@ -60,13 +62,6 @@ class Symphony extends AbstractBase
      */
     protected $policies;
 
-    /**
-     * Service locator
-     *
-     * @var ServiceLocatorInterface
-     */
-    protected $serviceLocator;
-
     /**
      * Logger (or false for none)
      *
@@ -1730,27 +1725,4 @@ class Symphony extends AbstractBase
             return $libraries[0]['locationID'];
         }
     }
-
-    /**
-     * Set the service locator.
-     *
-     * @param ServiceLocatorInterface $serviceLocator Locator to register
-     *
-     * @return Symphony
-     */
-    public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
-    {
-        $this->serviceLocator = $serviceLocator;
-        return $this;
-    }
-
-    /**
-     * Get the service locator.
-     *
-     * @return \Zend\ServiceManager\ServiceLocatorInterface
-     */
-    public function getServiceLocator()
-    {
-        return $this->serviceLocator;
-    }
 }
diff --git a/module/VuFind/src/VuFind/Log/Logger.php b/module/VuFind/src/VuFind/Log/Logger.php
index d048847c742..084bc96be2f 100644
--- a/module/VuFind/src/VuFind/Log/Logger.php
+++ b/module/VuFind/src/VuFind/Log/Logger.php
@@ -41,6 +41,8 @@ use Zend\Log\Logger as BaseLogger,
  */
 class Logger extends BaseLogger implements ServiceLocatorAwareInterface
 {
+    use \Zend\ServiceManager\ServiceLocatorAwareTrait;
+
     /**
      * Is debug logging enabled?
      *
@@ -48,13 +50,6 @@ class Logger extends BaseLogger implements ServiceLocatorAwareInterface
      */
     protected $debugNeeded = false;
 
-    /**
-     * Service locator
-     *
-     * @var ServiceLocatorInterface
-     */
-    protected $serviceLocator;
-
     /**
      * Set configuration
      *
@@ -228,29 +223,6 @@ class Logger extends BaseLogger implements ServiceLocatorAwareInterface
         return $this->debugNeeded;
     }
 
-    /**
-     * Set the service locator.
-     *
-     * @param ServiceLocatorInterface $serviceLocator Locator to register
-     *
-     * @return Logger
-     */
-    public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
-    {
-        $this->serviceLocator = $serviceLocator;
-        return $this;
-    }
-
-    /**
-     * Get the service locator.
-     *
-     * @return \Zend\ServiceManager\ServiceLocatorInterface
-     */
-    public function getServiceLocator()
-    {
-        return $this->serviceLocator;
-    }
-
     /**
      * Add a message as a log entry
      *
diff --git a/module/VuFind/src/VuFind/Search/Base/Params.php b/module/VuFind/src/VuFind/Search/Base/Params.php
index 6c4b90b5043..2affc69cf13 100644
--- a/module/VuFind/src/VuFind/Search/Base/Params.php
+++ b/module/VuFind/src/VuFind/Search/Base/Params.php
@@ -44,6 +44,10 @@ use VuFind\Search\QueryAdapter, VuFind\Solr\Utils as SolrUtils;
  */
 class Params implements ServiceLocatorAwareInterface
 {
+    use \Zend\ServiceManager\ServiceLocatorAwareTrait {
+        setServiceLocator as setServiceLocatorThroughTrait;
+    }
+
     /**
      * Internal representation of user query.
      *
@@ -154,13 +158,6 @@ class Params implements ServiceLocatorAwareInterface
      */
     protected $overrideQuery = false;
 
-    /**
-     * Service locator
-     *
-     * @var ServiceLocatorInterface
-     */
-    protected $serviceLocator;
-
     /**
      * Are default filters applied?
      *
@@ -1663,18 +1660,7 @@ class Params implements ServiceLocatorAwareInterface
         if ($serviceLocator instanceof ServiceLocatorAwareInterface) {
             $serviceLocator = $serviceLocator->getServiceLocator();
         }
-        $this->serviceLocator = $serviceLocator;
-        return $this;
-    }
-
-    /**
-     * Get the service locator.
-     *
-     * @return \Zend\ServiceManager\ServiceLocatorInterface
-     */
-    public function getServiceLocator()
-    {
-        return $this->serviceLocator;
+        return $this->setServiceLocatorThroughTrait($serviceLocator);
     }
 
     /**
diff --git a/module/VuFind/src/VuFind/Search/Base/Results.php b/module/VuFind/src/VuFind/Search/Base/Results.php
index a2d283b8e27..e7b73aa48ee 100644
--- a/module/VuFind/src/VuFind/Search/Base/Results.php
+++ b/module/VuFind/src/VuFind/Search/Base/Results.php
@@ -44,6 +44,10 @@ use VuFindSearch\Service as SearchService;
  */
 abstract class Results implements ServiceLocatorAwareInterface
 {
+    use \Zend\ServiceManager\ServiceLocatorAwareTrait {
+        setServiceLocator as setServiceLocatorThroughTrait;
+    }
+
     /**
      * Search parameters
      *
@@ -129,13 +133,6 @@ abstract class Results implements ServiceLocatorAwareInterface
      */
     protected $searchService;
 
-    /**
-     * Service locator
-     *
-     * @var ServiceLocatorInterface
-     */
-    protected $serviceLocator;
-
     /**
      * Constructor
      *
@@ -526,8 +523,7 @@ abstract class Results implements ServiceLocatorAwareInterface
         if ($serviceLocator instanceof ServiceLocatorAwareInterface) {
             $serviceLocator = $serviceLocator->getServiceLocator();
         }
-        $this->serviceLocator = $serviceLocator;
-        return $this;
+        return $this->setServiceLocatorThroughTrait($serviceLocator);
     }
 
     /**
@@ -566,16 +562,6 @@ abstract class Results implements ServiceLocatorAwareInterface
         return $vars;
     }
 
-    /**
-     * Get the service locator.
-     *
-     * @return \Zend\ServiceManager\ServiceLocatorInterface
-     */
-    public function getServiceLocator()
-    {
-        return $this->serviceLocator;
-    }
-
     /**
      * Return search service.
      *
diff --git a/module/VuFind/src/VuFind/XSLT/Importer.php b/module/VuFind/src/VuFind/XSLT/Importer.php
index 3a2e437f16e..972ce8d8ed9 100644
--- a/module/VuFind/src/VuFind/XSLT/Importer.php
+++ b/module/VuFind/src/VuFind/XSLT/Importer.php
@@ -43,12 +43,7 @@ use DOMDocument, VuFind\Config\Locator as ConfigLocator,
  */
 class Importer implements ServiceLocatorAwareInterface
 {
-    /**
-     * Service locator
-     *
-     * @var ServiceLocatorInterface
-     */
-    protected $serviceLocator;
+    use \Zend\ServiceManager\ServiceLocatorAwareTrait;
 
     /**
      * Save an XML file to the Solr index using the specified configuration.
@@ -191,27 +186,4 @@ class Importer implements ServiceLocatorAwareInterface
 
         return $xsl;
     }
-
-    /**
-     * Set the service locator.
-     *
-     * @param ServiceLocatorInterface $serviceLocator Locator to register
-     *
-     * @return Manager
-     */
-    public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
-    {
-        $this->serviceLocator = $serviceLocator;
-        return $this;
-    }
-
-    /**
-     * Get the service locator.
-     *
-     * @return \Zend\ServiceManager\ServiceLocatorInterface
-     */
-    public function getServiceLocator()
-    {
-        return $this->serviceLocator;
-    }
 }
-- 
GitLab