From 091797579e6be1e4393f36ca7716224c451da3b4 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Fri, 2 Feb 2018 13:11:35 -0500
Subject: [PATCH] Modernize record router service. - Use fully qualified class
 name as service name. - Eliminate static factory.

---
 module/VuFind/config/module.config.php        |  3 +-
 .../src/VuFind/ChannelProvider/Factory.php    |  4 +-
 .../src/VuFind/Controller/AbstractBase.php    |  2 +-
 .../src/VuFind/Record/RouterFactory.php       | 69 +++++++++++++++++++
 module/VuFind/src/VuFind/Service/Factory.php  | 15 ----
 .../src/VuFind/View/Helper/Root/Factory.php   |  2 +-
 6 files changed, 75 insertions(+), 20 deletions(-)
 create mode 100644 module/VuFind/src/VuFind/Record/RouterFactory.php

diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php
index 31dc357b3bb..9494505a072 100644
--- a/module/VuFind/config/module.config.php
+++ b/module/VuFind/config/module.config.php
@@ -321,8 +321,8 @@ $config = [
             'VuFind\Recommend\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory',
             'VuFind\Record\Cache' => 'VuFind\Record\CacheFactory',
             'VuFind\Record\Loader' => 'VuFind\Record\LoaderFactory',
+            'VuFind\Record\Router' => 'VuFind\Record\RouterFactory',
             'VuFind\RecordDriver\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory',
-            'VuFind\RecordRouter' => 'VuFind\Service\Factory::getRecordRouter',
             'VuFind\RecordTab\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory',
             'VuFind\Related\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory',
             'VuFind\Resolver\Driver\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory',
@@ -400,6 +400,7 @@ $config = [
             'VuFind\RecordCache' => 'VuFind\Record\Cache',
             'VuFind\RecordDriverPluginManager' => 'VuFind\RecordDriver\PluginManager',
             'VuFind\RecordLoader' => 'VuFind\Record\Loader',
+            'VuFind\RecordRouter' => 'VuFind\Record\Router',
             'VuFind\RecordTabPluginManager' => 'VuFind\RecordTab\PluginManager',
             'VuFind\RelatedPluginManager' => 'VuFind\Related\PluginManager',
             'VuFind\ResolverDriverPluginManager' => 'VuFind\Resolver\Driver\PluginManager',
diff --git a/module/VuFind/src/VuFind/ChannelProvider/Factory.php b/module/VuFind/src/VuFind/ChannelProvider/Factory.php
index 05f235bd1a9..5e9b9583c76 100644
--- a/module/VuFind/src/VuFind/ChannelProvider/Factory.php
+++ b/module/VuFind/src/VuFind/ChannelProvider/Factory.php
@@ -56,7 +56,7 @@ class Factory
             $sm->get('VuFind\Search\BackendManager')
                 ->get('Solr'),
             $sm->get('ControllerPluginManager')->get('url'),
-            $sm->get('VuFind\RecordRouter')
+            $sm->get('VuFind\Record\Router')
         );
         $helper->setCoverRouter(
             $sm->get('VuFind\Cover\Router')
@@ -134,7 +134,7 @@ class Factory
         $helper = new SimilarItems(
             $sm->get('VuFind\Search'),
             $sm->get('ControllerPluginManager')->get('url'),
-            $sm->get('VuFind\RecordRouter')
+            $sm->get('VuFind\Record\Router')
         );
         $helper->setCoverRouter(
             $sm->get('VuFind\Cover\Router')
diff --git a/module/VuFind/src/VuFind/Controller/AbstractBase.php b/module/VuFind/src/VuFind/Controller/AbstractBase.php
index 3c391aa25b5..20e96f50784 100644
--- a/module/VuFind/src/VuFind/Controller/AbstractBase.php
+++ b/module/VuFind/src/VuFind/Controller/AbstractBase.php
@@ -407,7 +407,7 @@ class AbstractBase extends AbstractActionController
      */
     public function getRecordRouter()
     {
-        return $this->serviceLocator->get('VuFind\RecordRouter');
+        return $this->serviceLocator->get('VuFind\Record\Router');
     }
 
     /**
diff --git a/module/VuFind/src/VuFind/Record/RouterFactory.php b/module/VuFind/src/VuFind/Record/RouterFactory.php
new file mode 100644
index 00000000000..3b00e07697c
--- /dev/null
+++ b/module/VuFind/src/VuFind/Record/RouterFactory.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * Record router factory.
+ *
+ * PHP version 5
+ *
+ * Copyright (C) Villanova University 2018.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * @category VuFind
+ * @package  Record
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     https://vufind.org/wiki/development Wiki
+ */
+namespace VuFind\Record;
+
+use Interop\Container\ContainerInterface;
+use Zend\ServiceManager\Factory\FactoryInterface;
+
+/**
+ * Record router factory.
+ *
+ * @category VuFind
+ * @package  Record
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     https://vufind.org/wiki/development Wiki
+ */
+class RouterFactory implements FactoryInterface
+{
+    /**
+     * Create an object
+     *
+     * @param ContainerInterface $container     Service manager
+     * @param string             $requestedName Service being created
+     * @param null|array         $options       Extra options (optional)
+     *
+     * @return object
+     *
+     * @throws ServiceNotFoundException if unable to resolve the service.
+     * @throws ServiceNotCreatedException if an exception is raised when
+     * creating a service.
+     * @throws ContainerException if any other error occurs
+     */
+    public function __invoke(ContainerInterface $container, $requestedName,
+        array $options = null
+    ) {
+        if (!empty($options)) {
+            throw new \Exception('Unexpected options passed to factory.');
+        }
+        return new $requestedName(
+            $container->get('VuFind\Record\Loader'),
+            $container->get('VuFind\Config\PluginManager')->get('config')
+        );
+    }
+}
diff --git a/module/VuFind/src/VuFind/Service/Factory.php b/module/VuFind/src/VuFind/Service/Factory.php
index b5e12810b57..6371114b3c6 100644
--- a/module/VuFind/src/VuFind/Service/Factory.php
+++ b/module/VuFind/src/VuFind/Service/Factory.php
@@ -116,21 +116,6 @@ class Factory
         return $config;
     }
 
-    /**
-     * Construct the record router.
-     *
-     * @param ServiceManager $sm Service manager.
-     *
-     * @return \VuFind\Record\Router
-     */
-    public static function getRecordRouter(ServiceManager $sm)
-    {
-        return new \VuFind\Record\Router(
-            $sm->get('VuFind\Record\Loader'),
-            $sm->get('VuFind\Config\PluginManager')->get('config')
-        );
-    }
-
     /**
      * Construct the search history helper.
      *
diff --git a/module/VuFind/src/VuFind/View/Helper/Root/Factory.php b/module/VuFind/src/VuFind/View/Helper/Root/Factory.php
index 68ac411633d..82c6d0cd3e8 100644
--- a/module/VuFind/src/VuFind/View/Helper/Root/Factory.php
+++ b/module/VuFind/src/VuFind/View/Helper/Root/Factory.php
@@ -434,7 +434,7 @@ class Factory
      */
     public static function getRecordLink(ServiceManager $sm)
     {
-        return new RecordLink($sm->get('VuFind\RecordRouter'));
+        return new RecordLink($sm->get('VuFind\Record\Router'));
     }
 
     /**
-- 
GitLab