From acb63d7b692dbf10a5110b6bd8fa3489e0ee157f Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Fri, 2 Feb 2018 13:30:27 -0500
Subject: [PATCH] Eliminate static factory.

---
 module/VuFind/config/module.config.php        |  2 +-
 module/VuFind/src/VuFind/Service/Factory.php  | 15 ----
 .../VuFind/src/VuFind/Solr/WriterFactory.php  | 69 +++++++++++++++++++
 3 files changed, 70 insertions(+), 16 deletions(-)
 create mode 100644 module/VuFind/src/VuFind/Solr/WriterFactory.php

diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php
index fe981a5344b..d4413d2e937 100644
--- a/module/VuFind/config/module.config.php
+++ b/module/VuFind/config/module.config.php
@@ -343,7 +343,7 @@ $config = [
             'VuFind\SessionManager' => 'VuFind\Session\ManagerFactory',
             'VuFind\SessionPluginManager' => 'VuFind\Service\Factory::getSessionPluginManager',
             'VuFind\SMS' => 'VuFind\SMS\Factory',
-            'VuFind\Solr\Writer' => 'VuFind\Service\Factory::getSolrWriter',
+            'VuFind\Solr\Writer' => 'VuFind\Solr\WriterFactory',
             'VuFind\Tags' => 'VuFind\Service\Factory::getTags',
             'VuFind\Translator' => 'VuFind\Service\Factory::getTranslator',
             'VuFind\WorldCatUtils' => 'VuFind\Service\Factory::getWorldCatUtils',
diff --git a/module/VuFind/src/VuFind/Service/Factory.php b/module/VuFind/src/VuFind/Service/Factory.php
index e0316ecea84..17e464493a4 100644
--- a/module/VuFind/src/VuFind/Service/Factory.php
+++ b/module/VuFind/src/VuFind/Service/Factory.php
@@ -194,21 +194,6 @@ class Factory
         return static::getGenericPluginManager($sm, 'Session');
     }
 
-    /**
-     * Construct the Solr writer.
-     *
-     * @param ServiceManager $sm Service manager.
-     *
-     * @return \VuFind\Solr\Writer
-     */
-    public static function getSolrWriter(ServiceManager $sm)
-    {
-        return new \VuFind\Solr\Writer(
-            $sm->get('VuFind\Search\BackendManager'),
-            $sm->get('VuFind\Db\Table\PluginManager')->get('changetracker')
-        );
-    }
-
     /**
      * Construct the tag helper.
      *
diff --git a/module/VuFind/src/VuFind/Solr/WriterFactory.php b/module/VuFind/src/VuFind/Solr/WriterFactory.php
new file mode 100644
index 00000000000..81ac7279a21
--- /dev/null
+++ b/module/VuFind/src/VuFind/Solr/WriterFactory.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * Solr writer 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  Search
+ * @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\Solr;
+
+use Interop\Container\ContainerInterface;
+use Zend\ServiceManager\Factory\FactoryInterface;
+
+/**
+ * Solr writer factory.
+ *
+ * @category VuFind
+ * @package  Search
+ * @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 WriterFactory 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 sent to factory.');
+        }
+        return new $requestedName(
+            $container->get('VuFind\Search\BackendManager'),
+            $container->get('VuFind\Db\Table\PluginManager')->get('changetracker')
+        );
+    }
+}
-- 
GitLab