From 6519cb0c59c160e246ffb25bdfb5f55d03a4c11c Mon Sep 17 00:00:00 2001 From: Chuck Hagenbuch Date: Sat, 27 Dec 2008 23:51:59 -0500 Subject: [PATCH] pass all dependencies in the constructor; get rid of setDbAdapter and setTableName methods --- content/app/controllers/TagController.php | 3 +-- content/bin/tag.php | 3 +-- content/bin/untag.php | 3 +-- content/lib/Objects/Manager.php | 23 +++-------------------- content/lib/Tagger.php | 23 +++-------------------- content/lib/Types/Manager.php | 23 +++-------------------- content/lib/Users/Manager.php | 23 +++-------------------- content/test/Tags/TaggerTest.php | 3 +-- 8 files changed, 16 insertions(+), 88 deletions(-) diff --git a/content/app/controllers/TagController.php b/content/app/controllers/TagController.php index 9c68c8ee3..d90b117de 100644 --- a/content/app/controllers/TagController.php +++ b/content/app/controllers/TagController.php @@ -15,8 +15,7 @@ class TagController extends Content_ApplicationController */ protected function _initialize() { - $this->tagger = new Content_Tagger(); - $this->tagger->setDbAdapter(Horde_Db::getAdapter()); + $this->tagger = new Content_Tagger(array('dbAdapter' => Horde_Db::getAdapter())); } /** diff --git a/content/bin/tag.php b/content/bin/tag.php index 93aa1df5c..f327753ae 100644 --- a/content/bin/tag.php +++ b/content/bin/tag.php @@ -17,7 +17,6 @@ if (!count($tags)) { throw new InvalidArgumentException('List at least one tag to add.'); } -$tagger = new Content_Tagger(); -$tagger->setDbAdapter(Horde_Db::getAdapter()); +$tagger = new Content_Tagger(array('dbAdapter' => Horde_Db::getAdapter())); $tagger->tag($opts->user_id, $opts->object_id, $tags); exit(0); diff --git a/content/bin/untag.php b/content/bin/untag.php index ccdd9fa0c..7e24da670 100644 --- a/content/bin/untag.php +++ b/content/bin/untag.php @@ -17,7 +17,6 @@ if (!count($tags)) { throw new InvalidArgumentException('List at least one tag to remove.'); } -$tagger = new Content_Tagger(); -$tagger->setDbAdapter(Horde_Db::getAdapter()); +$tagger = new Content_Tagger(array('dbAdapter' => Horde_Db::getAdapter())); $tagger->untag($opts->user_id, $opts->object_id, $tags); exit(0); diff --git a/content/lib/Objects/Manager.php b/content/lib/Objects/Manager.php index d9225e9e7..ec053ca34 100644 --- a/content/lib/Objects/Manager.php +++ b/content/lib/Objects/Manager.php @@ -52,27 +52,10 @@ class Content_Objects_Manager if (!empty($params['typeManager'])) { $this->_typeManager = $params['typeManager']; } - } - - /** - * Set the database connection. - * - * @param Horde_Db $db The database connection - */ - public function setDbAdapter($db) - { - $this->_db = $db; - } - /** - * Change the name of a database table. - * - * @param string $tableType - * @param string $tableName - */ - public function setTableName($tableType, $tableName) - { - $this->_tables[$tableType] = $tableName; + if (!empty($context['tables'])) { + $this->_tables = array_merge($this->_tables, $context['tables']); + } } /** diff --git a/content/lib/Tagger.php b/content/lib/Tagger.php index d697667ef..456289481 100644 --- a/content/lib/Tagger.php +++ b/content/lib/Tagger.php @@ -94,27 +94,10 @@ class Content_Tagger if (!empty($context['objectManager'])) { $this->_objectManager = $context['objectManager']; } - } - - /** - * Set the database connection for the tagger. - * - * @param Horde_Db $db - */ - public function setDbAdapter($db) - { - $this->_db = $db; - } - /** - * Change the name of a database table. - * - * @param string $tableType - * @param string $tableName - */ - public function setTableName($tableType, $tableName) - { - $this->_tables[$tableType] = $tableName; + if (!empty($context['tables'])) { + $this->_tables = array_merge($this->_tables, $context['tables']); + } } /** diff --git a/content/lib/Types/Manager.php b/content/lib/Types/Manager.php index 35d379a99..2761cccac 100644 --- a/content/lib/Types/Manager.php +++ b/content/lib/Types/Manager.php @@ -37,27 +37,10 @@ class Content_Types_Manager if (!empty($context['dbAdapter'])) { $this->_db = $context['dbAdapter']; } - } - - /** - * Set the database adapter. - * - * @param Horde_Db $db The database connection - */ - public function setDbAdapter($db) - { - $this->_db = $db; - } - /** - * Change the name of a database table. - * - * @param string $tableType - * @param string $tableName - */ - public function setTableName($tableType, $tableName) - { - $this->_tables[$tableType] = $tableName; + if (!empty($context['tables'])) { + $this->_tables = array_merge($this->_tables, $context['tables']); + } } /** diff --git a/content/lib/Users/Manager.php b/content/lib/Users/Manager.php index 638e28beb..4ca994ed4 100644 --- a/content/lib/Users/Manager.php +++ b/content/lib/Users/Manager.php @@ -37,27 +37,10 @@ class Content_Users_Manager if (!empty($context['dbAdapter'])) { $this->_db = $context['dbAdapter']; } - } - - /** - * Set the database connection. - * - * @param Horde_Db $db The database connection - */ - public function setDbAdapter($db) - { - $this->_db = $db; - } - /** - * Change the name of a database table. - * - * @param string $tableType - * @param string $tableName - */ - public function setTableName($tableType, $tableName) - { - $this->_tables[$tableType] = $tableName; + if (!empty($context['tables'])) { + $this->_tables = array_merge($this->_tables, $context['tables']); + } } /** diff --git a/content/test/Tags/TaggerTest.php b/content/test/Tags/TaggerTest.php index 1cdc2194a..9b59083f9 100644 --- a/content/test/Tags/TaggerTest.php +++ b/content/test/Tags/TaggerTest.php @@ -24,8 +24,7 @@ class Content_Tags_TaggerTest extends PHPUnit_Framework_TestCase )); // Create tagger - $this->tagger = new Content_Tagger(); - $this->tagger->setDbAdapter($this->db); + $this->tagger = new Content_Tagger(array('dbAdapter' => $this->db)); // Read sql schema file $statements = array(); -- 2.11.0