Add shortcuts for accessing columns in the Table, similar to TableDefinition
authorChuck Hagenbuch <chuck@horde.org>
Tue, 1 Jun 2010 02:56:11 +0000 (22:56 -0400)
committerChuck Hagenbuch <chuck@horde.org>
Tue, 1 Jun 2010 02:56:11 +0000 (22:56 -0400)
framework/Db/lib/Horde/Db/Adapter/Base/Table.php

index f0dfa0c..6e9cc5b 100644 (file)
@@ -21,7 +21,7 @@
  * @package    Horde_Db
  * @subpackage Adapter
  */
-class Horde_Db_Adapter_Base_Table
+class Horde_Db_Adapter_Base_Table implements ArrayAccess, IteratorAggregate
 {
     protected $_name;
     protected $_primaryKey;
@@ -117,6 +117,77 @@ class Horde_Db_Adapter_Base_Table
 
 
     /*##########################################################################
+    # Object composition
+    ##########################################################################*/
+
+    public function __get($key)
+    {
+        return $this->getColumn($key);
+    }
+
+    public function __isset($key)
+    {
+        return isset($this->_columns[$key]);
+    }
+
+
+    /*##########################################################################
+    # ArrayAccess
+    ##########################################################################*/
+
+    /**
+     * ArrayAccess: Check if the given offset exists
+     *
+     * @param   int     $offset
+     * @return  boolean
+     */
+    public function offsetExists($offset)
+    {
+        return isset($this->_columns[$column]);
+    }
+
+    /**
+     * ArrayAccess: Return the value for the given offset.
+     *
+     * @param   int     $offset
+     * @return  object  {@link {@Horde_Db_Adapter_Base_ColumnDefinition}
+     */
+    public function offsetGet($offset)
+    {
+        return $this->getColumn($offset);
+    }
+
+    /**
+     * ArrayAccess: Set value for given offset
+     *
+     * @param   int     $offset
+     * @param   mixed   $value
+     */
+    public function offsetSet($offset, $value)
+    {
+    }
+
+    /**
+     * ArrayAccess: remove element
+     *
+     * @param   int     $offset
+     */
+    public function offsetUnset($offset)
+    {
+    }
+
+
+    /*##########################################################################
+    # IteratorAggregate
+    ##########################################################################*/
+
+    public function getIterator()
+    {
+        return new ArrayIterator($this->_columns);
+    }
+
+
+    /*##########################################################################
     # Protected
     ##########################################################################*/