From b120b6cc222aa66a4bbf5c734e64876e27545add Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Mon, 12 Feb 2018 11:08:32 -0500
Subject: [PATCH] Modernize controller factory configuration. - Eliminate
 static factories. - Fix bug in VuFindAdmin\SocialstatsController
 configuration.

---
 module/VuFind/config/module.config.php        |  90 +++++-----
 .../Controller/AbstractBaseFactory.php}       |  37 ++++-
 .../AbstractBaseWithConfigFactory.php         |  67 ++++++++
 .../Controller/CartControllerFactory.php      |  69 ++++++++
 .../VuFind/src/VuFind/Controller/Factory.php  | 155 ------------------
 .../src/VuFind/Controller/GenericFactory.php  |  84 ----------
 .../Controller/IndexControllerFactory.php     |  68 ++++++++
 .../Controller/UpgradeControllerFactory.php   |  70 ++++++++
 module/VuFindAdmin/config/module.config.php   |  14 +-
 .../src/VuFindAdmin/Controller/Factory.php    |  43 -----
 module/VuFindConsole/config/module.config.php |  14 +-
 .../src/VuFindConsole/Controller/Factory.php  |  43 -----
 .../VuFindDevTools/config/module.config.php   |   2 +-
 13 files changed, 364 insertions(+), 392 deletions(-)
 rename module/{VuFindDevTools/src/VuFindDevTools/Controller/Factory.php => VuFind/src/VuFind/Controller/AbstractBaseFactory.php} (52%)
 create mode 100644 module/VuFind/src/VuFind/Controller/AbstractBaseWithConfigFactory.php
 create mode 100644 module/VuFind/src/VuFind/Controller/CartControllerFactory.php
 delete mode 100644 module/VuFind/src/VuFind/Controller/Factory.php
 delete mode 100644 module/VuFind/src/VuFind/Controller/GenericFactory.php
 create mode 100644 module/VuFind/src/VuFind/Controller/IndexControllerFactory.php
 create mode 100644 module/VuFind/src/VuFind/Controller/UpgradeControllerFactory.php
 delete mode 100644 module/VuFindAdmin/src/VuFindAdmin/Controller/Factory.php
 delete mode 100644 module/VuFindConsole/src/VuFindConsole/Controller/Factory.php

diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php
index 86dd1dcf826..9a1ed8be02c 100644
--- a/module/VuFind/config/module.config.php
+++ b/module/VuFind/config/module.config.php
@@ -105,51 +105,51 @@ $config = [
     ],
     'controllers' => [
         'factories' => [
-            'VuFind\Controller\AjaxController' => 'VuFind\Controller\Factory::getAjaxController',
-            'VuFind\Controller\AlphabrowseController' => 'VuFind\Controller\Factory::getAlphabrowseController',
-            'VuFind\Controller\AuthorController' => 'VuFind\Controller\Factory::getAuthorController',
-            'VuFind\Controller\AuthorityController' => 'VuFind\Controller\Factory::getAuthorityController',
-            'VuFind\Controller\BrowseController' => 'VuFind\Controller\Factory::getBrowseController',
-            'VuFind\Controller\BrowZineController' => 'VuFind\Controller\Factory::getBrowZineController',
-            'VuFind\Controller\CartController' => 'VuFind\Controller\Factory::getCartController',
-            'VuFind\Controller\ChannelsController' => 'VuFind\Controller\Factory::getChannelsController',
-            'VuFind\Controller\CollectionController' => 'VuFind\Controller\Factory::getCollectionController',
-            'VuFind\Controller\CollectionsController' => 'VuFind\Controller\Factory::getCollectionsController',
-            'VuFind\Controller\CombinedController' => 'VuFind\Controller\Factory::getCombinedController',
-            'VuFind\Controller\ConfirmController' => 'VuFind\Controller\Factory::getConfirmController',
-            'VuFind\Controller\ContentController' => 'VuFind\Controller\Factory::getContentController',
-            'VuFind\Controller\CoverController' => 'VuFind\Controller\Factory::getCoverController',
-            'VuFind\Controller\EdsController' => 'VuFind\Controller\Factory::getEdsController',
-            'VuFind\Controller\EdsrecordController' => 'VuFind\Controller\Factory::getEdsrecordController',
-            'VuFind\Controller\EITController' => 'VuFind\Controller\Factory::getEITController',
-            'VuFind\Controller\EITrecordController' => '\VuFind\Controller\Factory::getEITrecordController',
-            'VuFind\Controller\ErrorController' => 'VuFind\Controller\Factory::getErrorController',
-            'VuFind\Controller\ExternalAuthController' => 'VuFind\Controller\Factory::getExternalAuthController',
-            'VuFind\Controller\FeedbackController' => 'VuFind\Controller\Factory::getFeedbackController',
-            'VuFind\Controller\HelpController' => 'VuFind\Controller\Factory::getHelpController',
-            'VuFind\Controller\HierarchyController' => 'VuFind\Controller\Factory::getHierarchyController',
-            'VuFind\Controller\IndexController' => 'VuFind\Controller\Factory::getIndexController',
-            'VuFind\Controller\InstallController' => 'VuFind\Controller\Factory::getInstallController',
-            'VuFind\Controller\LibGuidesController' => 'VuFind\Controller\Factory::getLibGuidesController',
-            'VuFind\Controller\LibraryCardsController' => 'VuFind\Controller\Factory::getLibraryCardsController',
-            'VuFind\Controller\MissingrecordController' => 'VuFind\Controller\Factory::getMissingrecordController',
-            'VuFind\Controller\MyResearchController' => 'VuFind\Controller\Factory::getMyResearchController',
-            'VuFind\Controller\OaiController' => 'VuFind\Controller\Factory::getOaiController',
-            'VuFind\Controller\Pazpar2Controller' => 'VuFind\Controller\Factory::getPazpar2Controller',
-            'VuFind\Controller\PrimoController' => 'VuFind\Controller\Factory::getPrimoController',
-            'VuFind\Controller\PrimorecordController' => 'VuFind\Controller\Factory::getPrimorecordController',
-            'VuFind\Controller\QRCodeController' => 'VuFind\Controller\Factory::getQRCodeController',
-            'VuFind\Controller\RecordController' => 'VuFind\Controller\Factory::getRecordController',
-            'VuFind\Controller\RecordsController' => 'VuFind\Controller\Factory::getRecordsController',
-            'VuFind\Controller\SearchController' => 'VuFind\Controller\Factory::getSearchController',
-            'VuFind\Controller\ShibbolethLogoutNotificationController' => 'VuFind\Controller\Factory::getShibbolethLogoutNotificationController',
-            'VuFind\Controller\SummonController' => 'VuFind\Controller\Factory::getSummonController',
-            'VuFind\Controller\SummonrecordController' => 'VuFind\Controller\Factory::getSummonrecordController',
-            'VuFind\Controller\TagController' => 'VuFind\Controller\Factory::getTagController',
-            'VuFind\Controller\UpgradeController' => 'VuFind\Controller\Factory::getUpgradeController',
-            'VuFind\Controller\WebController' => 'VuFind\Controller\Factory::getWebController',
-            'VuFind\Controller\WorldcatController' => 'VuFind\Controller\Factory::getWorldcatController',
-            'VuFind\Controller\WorldcatrecordController' => 'VuFind\Controller\Factory::getWorldcatrecordController',
+            'VuFind\Controller\AjaxController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\AlphabrowseController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\AuthorController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\AuthorityController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\BrowseController' => 'VuFind\Controller\AbstractBaseWithConfigFactory',
+            'VuFind\Controller\BrowZineController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\CartController' => 'VuFind\Controller\CartControllerFactory',
+            'VuFind\Controller\ChannelsController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\CollectionController' => 'VuFind\Controller\AbstractBaseWithConfigFactory',
+            'VuFind\Controller\CollectionsController' => 'VuFind\Controller\AbstractBaseWithConfigFactory',
+            'VuFind\Controller\CombinedController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\ConfirmController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\ContentController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\CoverController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\EdsController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\EdsrecordController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\EITController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\EITrecordController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\ErrorController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\ExternalAuthController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\FeedbackController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\HelpController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\HierarchyController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\IndexController' => 'VuFind\Controller\IndexControllerFactory',
+            'VuFind\Controller\InstallController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\LibGuidesController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\LibraryCardsController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\MissingrecordController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\MyResearchController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\OaiController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\Pazpar2Controller' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\PrimoController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\PrimorecordController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\QRCodeController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\RecordController' => 'VuFind\Controller\AbstractBaseWithConfigFactory',
+            'VuFind\Controller\RecordsController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\SearchController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\ShibbolethLogoutNotificationController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\SummonController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\SummonrecordController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\TagController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\UpgradeController' => 'VuFind\Controller\UpgradeControllerFactory',
+            'VuFind\Controller\WebController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\WorldcatController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFind\Controller\WorldcatrecordController' => 'VuFind\Controller\AbstractBaseFactory',
         ],
         'aliases' => [
             'AJAX' => 'VuFind\Controller\AjaxController',
diff --git a/module/VuFindDevTools/src/VuFindDevTools/Controller/Factory.php b/module/VuFind/src/VuFind/Controller/AbstractBaseFactory.php
similarity index 52%
rename from module/VuFindDevTools/src/VuFindDevTools/Controller/Factory.php
rename to module/VuFind/src/VuFind/Controller/AbstractBaseFactory.php
index e6d7f514c01..56bfd93bf9e 100644
--- a/module/VuFindDevTools/src/VuFindDevTools/Controller/Factory.php
+++ b/module/VuFind/src/VuFind/Controller/AbstractBaseFactory.php
@@ -1,10 +1,10 @@
 <?php
 /**
- * Factory for controllers.
+ * Generic controller factory.
  *
  * PHP version 5
  *
- * Copyright (C) Villanova University 2014.
+ * 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,
@@ -25,19 +25,42 @@
  * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  * @link     https://vufind.org/wiki/development Wiki
  */
-namespace VuFindDevTools\Controller;
+namespace VuFind\Controller;
+
+use Interop\Container\ContainerInterface;
+use Zend\ServiceManager\Factory\FactoryInterface;
 
 /**
- * Factory for controllers.
+ * Generic controller factory.
  *
  * @category VuFind
  * @package  Controller
  * @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
- *
- * @codeCoverageIgnore
  */
-class Factory extends \VuFind\Controller\GenericFactory
+class AbstractBaseFactory 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);
+    }
 }
diff --git a/module/VuFind/src/VuFind/Controller/AbstractBaseWithConfigFactory.php b/module/VuFind/src/VuFind/Controller/AbstractBaseWithConfigFactory.php
new file mode 100644
index 00000000000..7a02ed71aa7
--- /dev/null
+++ b/module/VuFind/src/VuFind/Controller/AbstractBaseWithConfigFactory.php
@@ -0,0 +1,67 @@
+<?php
+/**
+ * Generic controller factory (with config injection).
+ *
+ * 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  Controller
+ * @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\Controller;
+
+use Interop\Container\ContainerInterface;
+use Zend\ServiceManager\Factory\FactoryInterface;
+
+/**
+ * Generic controller factory (with config injection).
+ *
+ * @category VuFind
+ * @package  Controller
+ * @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 AbstractBaseWithConfigFactory 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.');
+        }
+        $config = $container->get('VuFind\Config\PluginManager')->get('config');
+        return new $requestedName($container, $config);
+    }
+}
diff --git a/module/VuFind/src/VuFind/Controller/CartControllerFactory.php b/module/VuFind/src/VuFind/Controller/CartControllerFactory.php
new file mode 100644
index 00000000000..aeb4165b40e
--- /dev/null
+++ b/module/VuFind/src/VuFind/Controller/CartControllerFactory.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * Cart controller 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  Controller
+ * @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\Controller;
+
+use Interop\Container\ContainerInterface;
+use Zend\ServiceManager\Factory\FactoryInterface;
+
+/**
+ * Cart controller factory.
+ *
+ * @category VuFind
+ * @package  Controller
+ * @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 CartControllerFactory 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.');
+        }
+        $session = new \Zend\Session\Container(
+            'cart_followup', $container->get('Zend\Session\SessionManager')
+        );
+        return new $requestedName($container, $session);
+    }
+}
diff --git a/module/VuFind/src/VuFind/Controller/Factory.php b/module/VuFind/src/VuFind/Controller/Factory.php
deleted file mode 100644
index 579b1864f7a..00000000000
--- a/module/VuFind/src/VuFind/Controller/Factory.php
+++ /dev/null
@@ -1,155 +0,0 @@
-<?php
-/**
- * Factory for controllers.
- *
- * PHP version 5
- *
- * Copyright (C) Villanova University 2014.
- *
- * 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  Controller
- * @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\Controller;
-
-use Zend\ServiceManager\ServiceManager;
-
-/**
- * Factory for controllers.
- *
- * @category VuFind
- * @package  Controller
- * @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
- *
- * @codeCoverageIgnore
- */
-class Factory extends GenericFactory
-{
-    /**
-     * Construct the BrowseController.
-     *
-     * @param ServiceManager $sm Service manager.
-     *
-     * @return BrowseController
-     */
-    public static function getBrowseController(ServiceManager $sm)
-    {
-        return new BrowseController(
-            $sm,
-            $sm->get('VuFind\Config\PluginManager')->get('config')
-        );
-    }
-
-    /**
-     * Construct the CartController.
-     *
-     * @param ServiceManager $sm Service manager.
-     *
-     * @return BrowseController
-     */
-    public static function getCartController(ServiceManager $sm)
-    {
-        return new CartController(
-            $sm,
-            new \Zend\Session\Container(
-                'cart_followup',
-                $sm->get('Zend\Session\SessionManager')
-            )
-        );
-    }
-
-    /**
-     * Construct the CollectionController.
-     *
-     * @param ServiceManager $sm Service manager.
-     *
-     * @return CollectionController
-     */
-    public static function getCollectionController(ServiceManager $sm)
-    {
-        return new CollectionController(
-            $sm,
-            $sm->get('VuFind\Config\PluginManager')->get('config')
-        );
-    }
-
-    /**
-     * Construct the CollectionsController.
-     *
-     * @param ServiceManager $sm Service manager.
-     *
-     * @return CollectionsController
-     */
-    public static function getCollectionsController(ServiceManager $sm)
-    {
-        return new CollectionsController(
-            $sm,
-            $sm->get('VuFind\Config\PluginManager')->get('config')
-        );
-    }
-
-    /**
-     * Construct the IndexController.
-     *
-     * @param ServiceManager $sm Service manager.
-     *
-     * @return RecordController
-     */
-    public static function getIndexController(ServiceManager $sm)
-    {
-        return new IndexController(
-            $sm->get('VuFind\Config\PluginManager')->get('config'),
-            $sm->get('VuFind\Auth\Manager')
-        );
-    }
-
-    /**
-     * Construct the RecordController.
-     *
-     * @param ServiceManager $sm Service manager.
-     *
-     * @return RecordController
-     */
-    public static function getRecordController(ServiceManager $sm)
-    {
-        return new RecordController(
-            $sm,
-            $sm->get('VuFind\Config\PluginManager')->get('config')
-        );
-    }
-
-    /**
-     * Construct the UpgradeController.
-     *
-     * @param ServiceManager $sm Service manager.
-     *
-     * @return UpgradeController
-     */
-    public static function getUpgradeController(ServiceManager $sm)
-    {
-        return new UpgradeController(
-            $sm,
-            $sm->get('VuFind\Cookie\CookieManager'),
-            new \Zend\Session\Container(
-                'upgrade', $sm->get('Zend\Session\SessionManager')
-            )
-        );
-    }
-}
diff --git a/module/VuFind/src/VuFind/Controller/GenericFactory.php b/module/VuFind/src/VuFind/Controller/GenericFactory.php
deleted file mode 100644
index 66e12fcb164..00000000000
--- a/module/VuFind/src/VuFind/Controller/GenericFactory.php
+++ /dev/null
@@ -1,84 +0,0 @@
-<?php
-/**
- * Generic factory for controllers (contains generic default behavior shared
- * across VuFind's modules).
- *
- * PHP version 5
- *
- * Copyright (C) Villanova University 2017.
- *
- * 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  Controller
- * @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\Controller;
-
-use Zend\ServiceManager\ServiceManager;
-
-/**
- * Generic factory for controllers (contains generic default behavior shared
- * across VuFind's modules).
- *
- * @category VuFind
- * @package  Controller
- * @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
- *
- * @codeCoverageIgnore
- */
-class GenericFactory
-{
-    /**
-     * Construct a generic controller.
-     *
-     * @param string         $name Name of table to construct (fully qualified
-     * class name, or else a class name within the current namespace)
-     * @param ServiceManager $sm   Service manager
-     *
-     * @return object
-     */
-    public static function getGenericController($name, ServiceManager $sm)
-    {
-        // Prepend the current (inherited) namespace unless we receive a FQCN:
-        $class = (strpos($name, '\\') === false)
-            ? substr(static::class, 0, strrpos(static::class, '\\') + 1) . $name
-            : $name;
-        if (!class_exists($class)) {
-            throw new \Exception('Cannot construct ' . $class);
-        }
-        return new $class($sm);
-    }
-
-    /**
-     * Construct a generic controller.
-     *
-     * @param string $name Method name being called
-     * @param array  $args Method arguments
-     *
-     * @return object
-     */
-    public static function __callStatic($name, $args)
-    {
-        // Strip "get" from method name to get name of class; pass first argument
-        // on assumption that it should be the ServiceManager object.
-        return static::getGenericController(
-            substr($name, 3), isset($args[0]) ? $args[0] : null
-        );
-    }
-}
diff --git a/module/VuFind/src/VuFind/Controller/IndexControllerFactory.php b/module/VuFind/src/VuFind/Controller/IndexControllerFactory.php
new file mode 100644
index 00000000000..e05e020d5f7
--- /dev/null
+++ b/module/VuFind/src/VuFind/Controller/IndexControllerFactory.php
@@ -0,0 +1,68 @@
+<?php
+/**
+ * Index controller 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  Controller
+ * @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\Controller;
+
+use Interop\Container\ContainerInterface;
+use Zend\ServiceManager\Factory\FactoryInterface;
+
+/**
+ * Index controller factory.
+ *
+ * @category VuFind
+ * @package  Controller
+ * @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 IndexControllerFactory 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.');
+        }
+        $config = $container->get('VuFind\Config\PluginManager')->get('config');
+        $authManager = $container->get('VuFind\Auth\Manager');
+        return new $requestedName($config, $authManager);
+    }
+}
diff --git a/module/VuFind/src/VuFind/Controller/UpgradeControllerFactory.php b/module/VuFind/src/VuFind/Controller/UpgradeControllerFactory.php
new file mode 100644
index 00000000000..948a70292b8
--- /dev/null
+++ b/module/VuFind/src/VuFind/Controller/UpgradeControllerFactory.php
@@ -0,0 +1,70 @@
+<?php
+/**
+ * Upgrade controller 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  Controller
+ * @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\Controller;
+
+use Interop\Container\ContainerInterface;
+use Zend\ServiceManager\Factory\FactoryInterface;
+
+/**
+ * Upgrade controller factory.
+ *
+ * @category VuFind
+ * @package  Controller
+ * @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 UpgradeControllerFactory 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.');
+        }
+        $cookieManager = $container->get('VuFind\Cookie\CookieManager');
+        $session = new \Zend\Session\Container(
+            'upgrade', $container->get('Zend\Session\SessionManager')
+        );
+        return new $requestedName($container, $cookieManager, $session);
+    }
+}
diff --git a/module/VuFindAdmin/config/module.config.php b/module/VuFindAdmin/config/module.config.php
index 6dac6572877..d1b67adc4c2 100644
--- a/module/VuFindAdmin/config/module.config.php
+++ b/module/VuFindAdmin/config/module.config.php
@@ -4,18 +4,18 @@ namespace VuFindAdmin\Module\Configuration;
 $config = [
     'controllers' => [
         'factories' => [
-            'VuFindAdmin\Controller\AdminController' => 'VuFindAdmin\Controller\Factory::getAdminController',
-            'VuFindAdmin\Controller\ConfigController' => 'VuFindAdmin\Controller\Factory::getConfigController',
-            'VuFindAdmin\Controller\MaintenanceController' => 'VuFindAdmin\Controller\Factory::getMaintenanceController',
-            'VuFindAdmin\Controller\SocialController' => 'VuFindAdmin\Controller\Factory::getSocialstatsController',
-            'VuFindAdmin\Controller\StatisticsController' => 'VuFindAdmin\Controller\Factory::getStatisticsController',
-            'VuFindAdmin\Controller\TagsController' => 'VuFindAdmin\Controller\Factory::getTagsController',
+            'VuFindAdmin\Controller\AdminController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFindAdmin\Controller\ConfigController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFindAdmin\Controller\MaintenanceController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFindAdmin\Controller\SocialstatsController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFindAdmin\Controller\StatisticsController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFindAdmin\Controller\TagsController' => 'VuFind\Controller\AbstractBaseFactory',
         ],
         'aliases' => [
             'Admin' => 'VuFindAdmin\Controller\AdminController',
             'AdminConfig' => 'VuFindAdmin\Controller\ConfigController',
             'AdminMaintenance' => 'VuFindAdmin\Controller\MaintenanceController',
-            'AdminSocial' => 'VuFindAdmin\Controller\SocialController',
+            'AdminSocial' => 'VuFindAdmin\Controller\SocialstatsController',
             'AdminStatistics' => 'VuFindAdmin\Controller\StatisticsController',
             'AdminTags' => 'VuFindAdmin\Controller\TagsController',
         ],
diff --git a/module/VuFindAdmin/src/VuFindAdmin/Controller/Factory.php b/module/VuFindAdmin/src/VuFindAdmin/Controller/Factory.php
deleted file mode 100644
index c1b29d44202..00000000000
--- a/module/VuFindAdmin/src/VuFindAdmin/Controller/Factory.php
+++ /dev/null
@@ -1,43 +0,0 @@
-<?php
-/**
- * Factory for controllers.
- *
- * PHP version 5
- *
- * Copyright (C) Villanova University 2014.
- *
- * 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  Controller
- * @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 VuFindAdmin\Controller;
-
-/**
- * Factory for controllers.
- *
- * @category VuFind
- * @package  Controller
- * @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
- *
- * @codeCoverageIgnore
- */
-class Factory extends \VuFind\Controller\GenericFactory
-{
-}
diff --git a/module/VuFindConsole/config/module.config.php b/module/VuFindConsole/config/module.config.php
index 1cffe399803..fe5e16a7624 100644
--- a/module/VuFindConsole/config/module.config.php
+++ b/module/VuFindConsole/config/module.config.php
@@ -4,13 +4,13 @@ namespace VuFindConsole\Module\Configuration;
 $config = [
     'controllers' => [
         'factories' => [
-            'VuFindConsole\Controller\CompileController' => 'VuFindConsole\Controller\Factory::getCompileController',
-            'VuFindConsole\Controller\GenerateController' => 'VuFindConsole\Controller\Factory::getGenerateController',
-            'VuFindConsole\Controller\HarvestController' => 'VuFindConsole\Controller\Factory::getHarvestController',
-            'VuFindConsole\Controller\ImportController' => 'VuFindConsole\Controller\Factory::getImportController',
-            'VuFindConsole\Controller\LanguageController' => 'VuFindConsole\Controller\Factory::getLanguageController',
-            'VuFindConsole\Controller\RedirectController' => 'VuFindConsole\Controller\Factory::getRedirectController',
-            'VuFindConsole\Controller\UtilController' => 'VuFindConsole\Controller\Factory::getUtilController',
+            'VuFindConsole\Controller\CompileController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFindConsole\Controller\GenerateController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFindConsole\Controller\HarvestController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFindConsole\Controller\ImportController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFindConsole\Controller\LanguageController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFindConsole\Controller\RedirectController' => 'VuFind\Controller\AbstractBaseFactory',
+            'VuFindConsole\Controller\UtilController' => 'VuFind\Controller\AbstractBaseFactory',
         ],
         'aliases' => [
             'compile' => 'VuFindConsole\Controller\CompileController',
diff --git a/module/VuFindConsole/src/VuFindConsole/Controller/Factory.php b/module/VuFindConsole/src/VuFindConsole/Controller/Factory.php
deleted file mode 100644
index b3973c62f48..00000000000
--- a/module/VuFindConsole/src/VuFindConsole/Controller/Factory.php
+++ /dev/null
@@ -1,43 +0,0 @@
-<?php
-/**
- * Factory for controllers.
- *
- * PHP version 5
- *
- * Copyright (C) Villanova University 2014.
- *
- * 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  Controller
- * @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 VuFindConsole\Controller;
-
-/**
- * Factory for controllers.
- *
- * @category VuFind
- * @package  Controller
- * @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
- *
- * @codeCoverageIgnore
- */
-class Factory extends \VuFind\Controller\GenericFactory
-{
-}
diff --git a/module/VuFindDevTools/config/module.config.php b/module/VuFindDevTools/config/module.config.php
index ea761cd5800..9f95f2d302d 100644
--- a/module/VuFindDevTools/config/module.config.php
+++ b/module/VuFindDevTools/config/module.config.php
@@ -4,7 +4,7 @@ namespace VuFindLocalTemplate\Module\Configuration;
 $config = [
     'controllers' => [
         'factories' => [
-            'VuFindDevTools\Controller\DevtoolsController' => 'VuFindDevTools\Controller\Factory::getDevtoolsController',
+            'VuFindDevTools\Controller\DevtoolsController' => 'VuFind\Controller\AbstractBaseFactory',
         ],
         'aliases' => [
             'DevTools' => 'VuFindDevTools\Controller\DevtoolsController',
-- 
GitLab