diff --git a/module/VuFind/src/VuFind/Auth/AbstractBase.php b/module/VuFind/src/VuFind/Auth/AbstractBase.php index b33f4d398d999b6ac643a406b38ea846eef76c19..0f6a405449f789585f146034ae69dd04859f9869 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 689d1b33a7aacf199fe47b59c7016cb33ce28e11..d2ff8cfe5709e6f4f599c0d740defde568988c05 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 0000000000000000000000000000000000000000..6ceec21daedc7462cba8ed3fba35bdbf3ddd2e2a --- /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 f07e5d20370c4b933e789aa5e6ef660f589f2557..1543aa5dcc198033f8a5c20d5964500f88e78acc 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 0b560f3b4043b8fd2313dbd74355f2f837bdefa7..aa9b258706d20c09f87d0f09598679892ed57633 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 33399672eb9fb2a4f52586fbe5db6b042e115d4f..ea702c05ff199fe22e41c9cac5d47dd97692c2d0 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. *