From eb3a58fd8d3d75832f633df44cab9106c51d8a66 Mon Sep 17 00:00:00 2001 From: Chuck Hagenbuch Date: Mon, 31 May 2010 22:56:11 -0400 Subject: [PATCH] Add shortcuts for accessing columns in the Table, similar to TableDefinition --- framework/Db/lib/Horde/Db/Adapter/Base/Table.php | 73 +++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/framework/Db/lib/Horde/Db/Adapter/Base/Table.php b/framework/Db/lib/Horde/Db/Adapter/Base/Table.php index f0dfa0ca4..6e9cc5b48 100644 --- a/framework/Db/lib/Horde/Db/Adapter/Base/Table.php +++ b/framework/Db/lib/Horde/Db/Adapter/Base/Table.php @@ -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 ##########################################################################*/ -- 2.11.0