From 35cd3d92e47651caa543b8ae971959c7262d169c Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Thu, 23 Feb 2017 15:39:57 -0500
Subject: [PATCH] Remove ServiceLocatorAwareInterface from Symphony driver.
 (#929)

---
 module/VuFind/config/module.config.php        |  2 +-
 .../VuFind/src/VuFind/ILS/Driver/Factory.php  | 15 ++++++
 .../VuFind/src/VuFind/ILS/Driver/Symphony.php | 54 +++++++++++++------
 .../VuFindTest/ILS/Driver/SymphonyTest.php    |  9 ++--
 4 files changed, 59 insertions(+), 21 deletions(-)

diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php
index ad00baea39a..44f38d05fe6 100644
--- a/module/VuFind/config/module.config.php
+++ b/module/VuFind/config/module.config.php
@@ -435,6 +435,7 @@ $config = [
                     'noils' => 'VuFind\ILS\Driver\Factory::getNoILS',
                     'paia' => 'VuFind\ILS\Driver\Factory::getPAIA',
                     'kohailsdi' => 'VuFind\ILS\Driver\Factory::getKohaILSDI',
+                    'symphony' => 'VuFind\ILS\Driver\Factory::getSymphony',
                     'unicorn' => 'VuFind\ILS\Driver\Factory::getUnicorn',
                     'voyager' => 'VuFind\ILS\Driver\Factory::getVoyager',
                     'voyagerrestful' => 'VuFind\ILS\Driver\Factory::getVoyagerRestful',
@@ -449,7 +450,6 @@ $config = [
                     'polaris' => 'VuFind\ILS\Driver\Polaris',
                     'sample' => 'VuFind\ILS\Driver\Sample',
                     'sierra' => 'VuFind\ILS\Driver\Sierra',
-                    'symphony' => 'VuFind\ILS\Driver\Symphony',
                     'virtua' => 'VuFind\ILS\Driver\Virtua',
                     'xcncip2' => 'VuFind\ILS\Driver\XCNCIP2',
                 ],
diff --git a/module/VuFind/src/VuFind/ILS/Driver/Factory.php b/module/VuFind/src/VuFind/ILS/Driver/Factory.php
index c028f544234..472f1cf3d2d 100644
--- a/module/VuFind/src/VuFind/ILS/Driver/Factory.php
+++ b/module/VuFind/src/VuFind/ILS/Driver/Factory.php
@@ -196,6 +196,21 @@ class Factory
         return new KohaILSDI($sm->getServiceLocator()->get('VuFind\DateConverter'));
     }
 
+    /**
+     * Factory for Symphony driver.
+     *
+     * @param ServiceManager $sm Service manager.
+     *
+     * @return Symphony
+     */
+    public static function getSymphony(ServiceManager $sm)
+    {
+        return new Symphony(
+            $sm->getServiceLocator()->get('VuFind\RecordLoader'),
+            $sm->getServiceLocator()->get('VuFind\CacheManager')
+        );
+    }
+
     /**
      * Factory for Unicorn driver.
      *
diff --git a/module/VuFind/src/VuFind/ILS/Driver/Symphony.php b/module/VuFind/src/VuFind/ILS/Driver/Symphony.php
index e34f7f06b7d..50235a8eba1 100644
--- a/module/VuFind/src/VuFind/ILS/Driver/Symphony.php
+++ b/module/VuFind/src/VuFind/ILS/Driver/Symphony.php
@@ -27,9 +27,12 @@
  * @link     https://vufind.org/wiki/development:plugins:ils_drivers Wiki
  */
 namespace VuFind\ILS\Driver;
-use SoapClient, SoapFault, SoapHeader, VuFind\Exception\ILS as ILSException,
-    Zend\ServiceManager\ServiceLocatorAwareInterface,
-    Zend\ServiceManager\ServiceLocatorInterface;
+use SoapClient;
+use SoapFault;
+use SoapHeader;
+use VuFind\Cache\Manager as CacheManager;
+use VuFind\Exception\ILS as ILSException;
+use VuFind\Record\Loader;
 use Zend\Log\LoggerAwareInterface;
 
 /**
@@ -42,11 +45,9 @@ use Zend\Log\LoggerAwareInterface;
  * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  * @link     https://vufind.org/wiki/development:plugins:ils_drivers Wiki
  */
-class Symphony extends AbstractBase
-    implements ServiceLocatorAwareInterface, LoggerAwareInterface
+class Symphony extends AbstractBase implements LoggerAwareInterface
 {
     use \VuFind\Log\LoggerAwareTrait;
-    use \Zend\ServiceManager\ServiceLocatorAwareTrait;
 
     /**
      * Cache for policy information
@@ -62,6 +63,32 @@ class Symphony extends AbstractBase
      */
     protected $policies;
 
+    /**
+     * Cache manager
+     *
+     * @var CacheManager
+     */
+    protected $cacheManager;
+
+    /**
+     * Record loader
+     *
+     * @var Loader
+     */
+    protected $recordLoader;
+
+    /**
+     * Constructor
+     *
+     * @param Loader       $loader       Record loader
+     * @param CacheManager $cacheManager Cache manager (optional)
+     */
+    public function __construct(Loader $loader, CacheManager $cacheManager = null)
+    {
+        $this->recordLoader = $loader;
+        $this->cacheManager = $cacheManager;
+    }
+
     /**
      * Initialize the driver.
      *
@@ -120,13 +147,11 @@ class Symphony extends AbstractBase
         ];
 
         // Initialize cache manager.
-        if (isset($configArray['PolicyCache']['type'])) {
-            $serviceManager = $this->getServiceLocator()->getServiceLocator();
-            if ($serviceManager->has('VuFind\CacheManager')) {
-                $manager = $serviceManager->get('VuFind\CacheManager');
-                $this->policyCache
-                    = $manager->getCache($configArray['PolicyCache']['type']);
-            }
+        if (isset($configArray['PolicyCache']['type'])
+            && $this->cacheManager
+        ) {
+            $this->policyCache = $this->cacheManager
+                ->getCache($configArray['PolicyCache']['type']);
         }
     }
 
@@ -375,8 +400,7 @@ class Symphony extends AbstractBase
 
         $entryNumber = $this->config['999Holdings']['entry_number'];
 
-        $records = $this->getServiceLocator()->getServiceLocator()
-            ->get('VuFind\RecordLoader')->loadBatch($ids);
+        $records = $this->recordLoader->loadBatch($ids);
         foreach ($records as $record) {
             $results = $record->getFormattedMarcDetails($entryNumber, $marcMap);
             foreach ($results as $result) {
diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/SymphonyTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/SymphonyTest.php
index 88afb6c84c9..d5682b73070 100644
--- a/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/SymphonyTest.php
+++ b/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/SymphonyTest.php
@@ -46,7 +46,10 @@ class SymphonyTest extends \VuFindTest\Unit\TestCase
      */
     public function __construct()
     {
-        $this->driver = new Symphony();
+        $loader = $this->getMockBuilder('VuFind\Record\Loader')
+            ->disableOriginalConstructor()->getMock();
+
+        $this->driver = new Symphony($loader);
     }
 
     /**
@@ -56,10 +59,6 @@ class SymphonyTest extends \VuFindTest\Unit\TestCase
      */
     public function testBadBaseUrl()
     {
-        if (!version_compare(\PHP_VERSION, '5.3.4', '>=')) {
-            $this->markTestSkipped('Test requires PHP >= 5.3.4 (see VUFIND-660)');
-        }
-
         // Without SOAP functionality, we can't proceed:
         if (!class_exists('SoapClient')) {
             $this->markTestSkipped('SoapClient not installed');
-- 
GitLab