From 5ef895413fa47130eb497c281ebb6ffac744aba0 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Fri, 6 Feb 2015 12:02:31 -0500 Subject: [PATCH] Created DbTableAwareTrait. --- .../VuFind/src/VuFind/Auth/AbstractBase.php | 34 +-------- module/VuFind/src/VuFind/Autocomplete/Tag.php | 33 +-------- .../src/VuFind/Db/Table/DbTableAwareTrait.php | 73 +++++++++++++++++++ .../src/VuFind/RecordDriver/AbstractBase.php | 34 +-------- .../src/VuFind/Session/AbstractBase.php | 35 +-------- .../src/VuFind/Statistics/Driver/Db.php | 33 +-------- 6 files changed, 79 insertions(+), 163 deletions(-) create mode 100644 module/VuFind/src/VuFind/Db/Table/DbTableAwareTrait.php diff --git a/module/VuFind/src/VuFind/Auth/AbstractBase.php b/module/VuFind/src/VuFind/Auth/AbstractBase.php index b33f4d398d9..0f6a405449f 100644 --- a/module/VuFind/src/VuFind/Auth/AbstractBase.php +++ b/module/VuFind/src/VuFind/Auth/AbstractBase.php @@ -43,6 +43,7 @@ use Zend\Log\LoggerInterface; abstract class AbstractBase implements \VuFind\Db\Table\DbTableAwareInterface, \VuFind\I18n\Translator\TranslatorAwareInterface, \Zend\Log\LoggerAwareInterface { + use \VuFind\Db\Table\DbTableAwareTrait; use \VuFind\I18n\Translator\TranslatorAwareTrait; /** @@ -59,13 +60,6 @@ abstract class AbstractBase implements \VuFind\Db\Table\DbTableAwareInterface, */ protected $config = null; - /** - * Database table plugin manager - * - * @var \VuFind\Db\Table\PluginManager - */ - protected $tableManager; - /** * Logger (or false for none) * @@ -312,32 +306,6 @@ abstract class AbstractBase implements \VuFind\Db\Table\DbTableAwareInterface, return $this->getDbTableManager()->get('User'); } - /** - * Get the table plugin manager. Throw an exception if it is missing. - * - * @throws \Exception - * @return \VuFind\Db\Table\PluginManager - */ - public function getDbTableManager() - { - if (null === $this->tableManager) { - throw new \Exception('DB table manager missing.'); - } - return $this->tableManager; - } - - /** - * Set the table plugin manager. - * - * @param \VuFind\Db\Table\PluginManager $manager Plugin manager - * - * @return void - */ - public function setDbTableManager(\VuFind\Db\Table\PluginManager $manager) - { - $this->tableManager = $manager; - } - /** * Verify that a password fulfills the password policy. Throws exception if * the password is invalid. diff --git a/module/VuFind/src/VuFind/Autocomplete/Tag.php b/module/VuFind/src/VuFind/Autocomplete/Tag.php index 689d1b33a7a..d2ff8cfe570 100644 --- a/module/VuFind/src/VuFind/Autocomplete/Tag.php +++ b/module/VuFind/src/VuFind/Autocomplete/Tag.php @@ -40,12 +40,7 @@ namespace VuFind\Autocomplete; */ class Tag implements AutocompleteInterface, \VuFind\Db\Table\DbTableAwareInterface { - /** - * Database table plugin manager - * - * @var \VuFind\Db\Table\PluginManager - */ - protected $tableManager; + use \VuFind\Db\Table\DbTableAwareTrait; /** * getSuggestions @@ -94,30 +89,4 @@ class Tag implements AutocompleteInterface, \VuFind\Db\Table\DbTableAwareInterfa { return $this->getDbTableManager()->get('Tags'); } - - /** - * Get the table plugin manager. Throw an exception if it is missing. - * - * @throws \Exception - * @return \VuFind\Db\Table\PluginManager - */ - public function getDbTableManager() - { - if (null === $this->tableManager) { - throw new \Exception('DB table manager missing.'); - } - return $this->tableManager; - } - - /** - * Set the table plugin manager. - * - * @param \VuFind\Db\Table\PluginManager $manager Plugin manager - * - * @return void - */ - public function setDbTableManager(\VuFind\Db\Table\PluginManager $manager) - { - $this->tableManager = $manager; - } } diff --git a/module/VuFind/src/VuFind/Db/Table/DbTableAwareTrait.php b/module/VuFind/src/VuFind/Db/Table/DbTableAwareTrait.php new file mode 100644 index 00000000000..6ceec21daed --- /dev/null +++ b/module/VuFind/src/VuFind/Db/Table/DbTableAwareTrait.php @@ -0,0 +1,73 @@ +<?php +/** + * Default implementation of DbTableAwareInterface. + * + * PHP version 5 + * + * Copyright (C) Villanova University 2015. + * + * 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_Table + * @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\Table; + +/** + * Default implementation of DbTableAwareInterface. + * + * @category VuFind2 + * @package Db_Table + * @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 + */ +trait DbTableAwareTrait +{ + /** + * Database table plugin manager + * + * @var \VuFind\Db\Table\PluginManager + */ + protected $tableManager; + + /** + * Get the table plugin manager. Throw an exception if it is missing. + * + * @throws \Exception + * @return \VuFind\Db\Table\PluginManager + */ + public function getDbTableManager() + { + if (null === $this->tableManager) { + throw new \Exception('DB table manager missing.'); + } + return $this->tableManager; + } + + /** + * Set the table plugin manager. + * + * @param \VuFind\Db\Table\PluginManager $manager Plugin manager + * + * @return void + */ + public function setDbTableManager(\VuFind\Db\Table\PluginManager $manager) + { + $this->tableManager = $manager; + } +} \ No newline at end of file diff --git a/module/VuFind/src/VuFind/RecordDriver/AbstractBase.php b/module/VuFind/src/VuFind/RecordDriver/AbstractBase.php index f07e5d20370..1543aa5dcc1 100644 --- a/module/VuFind/src/VuFind/RecordDriver/AbstractBase.php +++ b/module/VuFind/src/VuFind/RecordDriver/AbstractBase.php @@ -44,6 +44,7 @@ abstract class AbstractBase implements \VuFind\Db\Table\DbTableAwareInterface, \VuFind\I18n\Translator\TranslatorAwareInterface, \VuFindSearch\Response\RecordInterface { + use \VuFind\Db\Table\DbTableAwareTrait; use \VuFind\I18n\Translator\TranslatorAwareTrait; /** @@ -81,13 +82,6 @@ abstract class AbstractBase implements \VuFind\Db\Table\DbTableAwareInterface, */ protected $fields = array(); - /** - * Database table plugin manager - * - * @var \VuFind\Db\Table\PluginManager - */ - protected $tableManager; - /** * Constructor * @@ -504,30 +498,4 @@ abstract class AbstractBase implements \VuFind\Db\Table\DbTableAwareInterface, { return $this->getDbTableManager()->get($table); } - - /** - * Get the table plugin manager. Throw an exception if it is missing. - * - * @throws \Exception - * @return \VuFind\Db\Table\PluginManager - */ - public function getDbTableManager() - { - if (null === $this->tableManager) { - throw new \Exception('DB table manager missing.'); - } - return $this->tableManager; - } - - /** - * Set the table plugin manager. - * - * @param \VuFind\Db\Table\PluginManager $manager Plugin manager - * - * @return void - */ - public function setDbTableManager(\VuFind\Db\Table\PluginManager $manager) - { - $this->tableManager = $manager; - } } diff --git a/module/VuFind/src/VuFind/Session/AbstractBase.php b/module/VuFind/src/VuFind/Session/AbstractBase.php index 0b560f3b404..aa9b258706d 100644 --- a/module/VuFind/src/VuFind/Session/AbstractBase.php +++ b/module/VuFind/src/VuFind/Session/AbstractBase.php @@ -40,6 +40,8 @@ use Zend\Session\SaveHandler\SaveHandlerInterface; abstract class AbstractBase implements SaveHandlerInterface, \VuFind\Db\Table\DbTableAwareInterface { + use \VuFind\Db\Table\DbTableAwareTrait; + /** * Session lifetime in seconds * @@ -54,13 +56,6 @@ abstract class AbstractBase implements SaveHandlerInterface, */ protected $config = null; - /** - * Database table plugin manager - * - * @var \VuFind\Db\Table\PluginManager - */ - protected $tableManager; - /** * Set configuration. * @@ -145,32 +140,6 @@ abstract class AbstractBase implements SaveHandlerInterface, // Something to keep in mind though. } - /** - * Get the table plugin manager. Throw an exception if it is missing. - * - * @throws \Exception - * @return \VuFind\Db\Table\PluginManager - */ - public function getDbTableManager() - { - if (null === $this->tableManager) { - throw new \Exception('DB table manager missing.'); - } - return $this->tableManager; - } - - /** - * Set the table plugin manager. - * - * @param \VuFind\Db\Table\PluginManager $manager Plugin manager - * - * @return void - */ - public function setDbTableManager(\VuFind\Db\Table\PluginManager $manager) - { - $this->tableManager = $manager; - } - /** * Get a database table object. * diff --git a/module/VuFind/src/VuFind/Statistics/Driver/Db.php b/module/VuFind/src/VuFind/Statistics/Driver/Db.php index 33399672eb9..ea702c05ff1 100644 --- a/module/VuFind/src/VuFind/Statistics/Driver/Db.php +++ b/module/VuFind/src/VuFind/Statistics/Driver/Db.php @@ -38,12 +38,7 @@ namespace VuFind\Statistics\Driver; */ class Db extends AbstractBase implements \VuFind\Db\Table\DbTableAwareInterface { - /** - * Database table plugin manager - * - * @var \VuFind\Db\Table\PluginManager - */ - protected $tableManager; + use \VuFind\Db\Table\DbTableAwareTrait; /** * Write a message to the log. @@ -94,32 +89,6 @@ class Db extends AbstractBase implements \VuFind\Db\Table\DbTableAwareInterface return $userStats->getBrowserStats($version, $limit); } - /** - * Get the table plugin manager. Throw an exception if it is missing. - * - * @throws \Exception - * @return \VuFind\Db\Table\PluginManager - */ - public function getDbTableManager() - { - if (null === $this->tableManager) { - throw new \Exception('DB table manager missing.'); - } - return $this->tableManager; - } - - /** - * Set the table plugin manager. - * - * @param \VuFind\Db\Table\PluginManager $manager Plugin manager - * - * @return void - */ - public function setDbTableManager(\VuFind\Db\Table\PluginManager $manager) - { - $this->tableManager = $manager; - } - /** * Get a database table object. * -- GitLab