pass all dependencies in the constructor; get rid of setDbAdapter and setTableName...
authorChuck Hagenbuch <chuck@horde.org>
Sun, 28 Dec 2008 04:51:59 +0000 (23:51 -0500)
committerChuck Hagenbuch <chuck@horde.org>
Sun, 28 Dec 2008 04:51:59 +0000 (23:51 -0500)
content/app/controllers/TagController.php
content/bin/tag.php
content/bin/untag.php
content/lib/Objects/Manager.php
content/lib/Tagger.php
content/lib/Types/Manager.php
content/lib/Users/Manager.php
content/test/Tags/TaggerTest.php

index 9c68c8e..d90b117 100644 (file)
@@ -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()));
     }
 
     /**
index 93aa1df..f327753 100644 (file)
@@ -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);
index ccdd9fa..7e24da6 100644 (file)
@@ -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);
index d9225e9..ec053ca 100644 (file)
@@ -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']);
+        }
     }
 
     /**
index d697667..4562894 100644 (file)
@@ -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']);
+        }
     }
 
     /**
index 35d379a..2761ccc 100644 (file)
@@ -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']);
+        }
     }
 
     /**
index 638e28b..4ca994e 100644 (file)
@@ -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']);
+        }
     }
 
     /**
index 1cdc219..9b59083 100644 (file)
@@ -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();