From eaa7396dc35904dc0a0c59a742dcf6230a51c297 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Fri, 6 Feb 2015 13:38:44 -0500
Subject: [PATCH] Eliminated need for ServiceLocatorAwareGateway.

---
 module/VuFind/src/VuFind/Db/Row/Resource.php  |  4 +-
 .../Db/Row/ServiceLocatorAwareGateway.php     | 57 -------------------
 module/VuFind/src/VuFind/Db/Row/Tags.php      |  4 +-
 module/VuFind/src/VuFind/Db/Row/User.php      |  4 +-
 module/VuFind/src/VuFind/Db/Row/UserList.php  |  4 +-
 .../src/VuFind/Db/Table/DbTableAwareTrait.php | 12 ++++
 module/VuFind/src/VuFind/Db/Table/Gateway.php |  3 +
 .../src/VuFind/RecordDriver/AbstractBase.php  | 12 ----
 8 files changed, 27 insertions(+), 73 deletions(-)
 delete mode 100644 module/VuFind/src/VuFind/Db/Row/ServiceLocatorAwareGateway.php

diff --git a/module/VuFind/src/VuFind/Db/Row/Resource.php b/module/VuFind/src/VuFind/Db/Row/Resource.php
index b4ac82b7b75..19f299f20e9 100644
--- a/module/VuFind/src/VuFind/Db/Row/Resource.php
+++ b/module/VuFind/src/VuFind/Db/Row/Resource.php
@@ -39,8 +39,10 @@ use VuFind\Date\Converter as DateConverter,
  * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  * @link     http://vufind.org   Main Site
  */
-class Resource extends ServiceLocatorAwareGateway
+class Resource extends RowGateway implements \VuFind\Db\Table\DbTableAwareInterface
 {
+    use \VuFind\Db\Table\DbTableAwareTrait;
+
     /**
      * Constructor
      *
diff --git a/module/VuFind/src/VuFind/Db/Row/ServiceLocatorAwareGateway.php b/module/VuFind/src/VuFind/Db/Row/ServiceLocatorAwareGateway.php
deleted file mode 100644
index 99d40adbc44..00000000000
--- a/module/VuFind/src/VuFind/Db/Row/ServiceLocatorAwareGateway.php
+++ /dev/null
@@ -1,57 +0,0 @@
-<?php
-/**
- * Abstract base class for rows that need access to the service locator.
- *
- * PHP version 5
- *
- * Copyright (C) Villanova University 2010.
- *
- * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * @category VuFind2
- * @package  Db_Row
- * @author   Demian Katz <demian.katz@villanova.edu>
- * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
- * @link     http://vufind.org   Main Site
- */
-namespace VuFind\Db\Row;
-use Zend\ServiceManager\ServiceLocatorAwareInterface,
-    Zend\ServiceManager\ServiceLocatorInterface;
-
-/**
- * Abstract base class for rows that need access to the service locator.
- *
- * @category VuFind2
- * @package  Db_Row
- * @author   Demian Katz <demian.katz@villanova.edu>
- * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
- * @link     http://vufind.org   Main Site
- */
-class ServiceLocatorAwareGateway extends RowGateway
-    implements ServiceLocatorAwareInterface
-{
-    use \Zend\ServiceManager\ServiceLocatorAwareTrait;
-
-    /**
-     * Get access to another table.
-     *
-     * @param string $table Table name
-     *
-     * @return \VuFind\Db\Table\Gateway
-     */
-    public function getDbTable($table)
-    {
-        return $this->getServiceLocator()->get($table);
-    }
-}
diff --git a/module/VuFind/src/VuFind/Db/Row/Tags.php b/module/VuFind/src/VuFind/Db/Row/Tags.php
index bef3ff3a028..4f8c8b84c5d 100644
--- a/module/VuFind/src/VuFind/Db/Row/Tags.php
+++ b/module/VuFind/src/VuFind/Db/Row/Tags.php
@@ -37,8 +37,10 @@ use VuFind\Db\Table\Resource as ResourceTable, Zend\Db\Sql\Expression;
  * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  * @link     http://vufind.org   Main Site
  */
-class Tags extends ServiceLocatorAwareGateway
+class Tags extends RowGateway implements \VuFind\Db\Table\DbTableAwareInterface
 {
+    use \VuFind\Db\Table\DbTableAwareTrait;
+
     /**
      * Constructor
      *
diff --git a/module/VuFind/src/VuFind/Db/Row/User.php b/module/VuFind/src/VuFind/Db/Row/User.php
index 5cfe5fd889b..583f12f02a2 100644
--- a/module/VuFind/src/VuFind/Db/Row/User.php
+++ b/module/VuFind/src/VuFind/Db/Row/User.php
@@ -42,8 +42,10 @@ use Zend\Db\Sql\Expression,
  * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  * @link     http://vufind.org   Main Site
  */
-class User extends ServiceLocatorAwareGateway
+class User extends RowGateway implements \VuFind\Db\Table\DbTableAwareInterface
 {
+    use \VuFind\Db\Table\DbTableAwareTrait;
+
     /**
      * Is encryption enabled?
      *
diff --git a/module/VuFind/src/VuFind/Db/Row/UserList.php b/module/VuFind/src/VuFind/Db/Row/UserList.php
index d6b32afa3bd..c1e2e5edaa1 100644
--- a/module/VuFind/src/VuFind/Db/Row/UserList.php
+++ b/module/VuFind/src/VuFind/Db/Row/UserList.php
@@ -39,8 +39,10 @@ use VuFind\Exception\ListPermission as ListPermissionException,
  * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  * @link     http://vufind.org   Main Site
  */
-class UserList extends ServiceLocatorAwareGateway
+class UserList extends RowGateway implements \VuFind\Db\Table\DbTableAwareInterface
 {
+    use \VuFind\Db\Table\DbTableAwareTrait;
+
     /**
      * Constructor
      *
diff --git a/module/VuFind/src/VuFind/Db/Table/DbTableAwareTrait.php b/module/VuFind/src/VuFind/Db/Table/DbTableAwareTrait.php
index 6ceec21daed..5dc23c54fd8 100644
--- a/module/VuFind/src/VuFind/Db/Table/DbTableAwareTrait.php
+++ b/module/VuFind/src/VuFind/Db/Table/DbTableAwareTrait.php
@@ -70,4 +70,16 @@ trait DbTableAwareTrait
     {
         $this->tableManager = $manager;
     }
+
+    /**
+     * Get a database table object.
+     *
+     * @param string $table Table to load.
+     *
+     * @return Gateway
+     */
+    public function getDbTable($table)
+    {
+        return $this->getDbTableManager()->get($table);
+    }
 }
\ No newline at end of file
diff --git a/module/VuFind/src/VuFind/Db/Table/Gateway.php b/module/VuFind/src/VuFind/Db/Table/Gateway.php
index 05b5698241c..474abc0c93c 100644
--- a/module/VuFind/src/VuFind/Db/Table/Gateway.php
+++ b/module/VuFind/src/VuFind/Db/Table/Gateway.php
@@ -122,6 +122,9 @@ class Gateway extends AbstractTableGateway implements ServiceLocatorAwareInterfa
         if ($prototype instanceof ServiceLocatorAwareInterface) {
             $prototype->setServiceLocator($this->getServiceLocator());
         }
+        \VuFind\ServiceManager\Initializer::initInstance(
+            $prototype, $this->getServiceLocator()->getServiceLocator()
+        );
         return $prototype;
     }
 
diff --git a/module/VuFind/src/VuFind/RecordDriver/AbstractBase.php b/module/VuFind/src/VuFind/RecordDriver/AbstractBase.php
index 1543aa5dcc1..dd05b3ea869 100644
--- a/module/VuFind/src/VuFind/RecordDriver/AbstractBase.php
+++ b/module/VuFind/src/VuFind/RecordDriver/AbstractBase.php
@@ -486,16 +486,4 @@ abstract class AbstractBase implements \VuFind\Db\Table\DbTableAwareInterface,
             ? call_user_func_array(array($this, $method), $params)
             : null;
     }
-
-    /**
-     * Get a database table object.
-     *
-     * @param string $table Table to load.
-     *
-     * @return \VuFind\Db\Table\User
-     */
-    public function getDbTable($table)
-    {
-        return $this->getDbTableManager()->get($table);
-    }
 }
-- 
GitLab