From: Chuck Hagenbuch Date: Sat, 10 Jan 2009 16:11:23 +0000 (-0500) Subject: add initial Table object for retrieving schema info in one object X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=22a713066e0f51874f5c4916ef118971659e9209;p=horde.git add initial Table object for retrieving schema info in one object --- diff --git a/framework/Db/lib/Horde/Db/Adapter/Abstract/Schema.php b/framework/Db/lib/Horde/Db/Adapter/Abstract/Schema.php index 58599c95c..edf7100a7 100644 --- a/framework/Db/lib/Horde/Db/Adapter/Abstract/Schema.php +++ b/framework/Db/lib/Horde/Db/Adapter/Abstract/Schema.php @@ -245,6 +245,23 @@ abstract class Horde_Db_Adapter_Abstract_Schema abstract public function tables($name = null); /** + * Get a Horde_Db_Adapter_Abstract_Table object for the table. + * + * @param string $tableName + * @param string $name + * + * @return Horde_Db_Adapter_Abstract_Table + */ + public function table($tableName, $name = null) + { + return $this->componentFactory('Table', array( + $tableName, + $this->columns($tableName, $name), + $this->indexes($tableName, $name), + )); + } + + /** * Return a table's primary key */ abstract public function primaryKey($tableName, $name = null); diff --git a/framework/Db/lib/Horde/Db/Adapter/Abstract/Table.php b/framework/Db/lib/Horde/Db/Adapter/Abstract/Table.php new file mode 100644 index 000000000..f948e29e7 --- /dev/null +++ b/framework/Db/lib/Horde/Db/Adapter/Abstract/Table.php @@ -0,0 +1,114 @@ + + * @author Derek DeVries + * @author Chuck Hagenbuch + * @license http://opensource.org/licenses/bsd-license.php + * @category Horde + * @package Horde_Db + * @subpackage Adapter + */ + +/** + * @author Mike Naberezny + * @author Derek DeVries + * @author Chuck Hagenbuch + * @license http://opensource.org/licenses/bsd-license.php + * @category Horde + * @package Horde_Db + * @subpackage Adapter + */ +class Horde_Db_Adapter_Abstract_Table +{ + protected $_name; + protected $_primaryKey; + protected $_columns; + protected $_indexes; + + + /*########################################################################## + # Construct/Destruct + ##########################################################################*/ + + /** + * Construct + * + * @param string $name The table's name, such as supplier_id in supplier_id int(11). + */ + public function __construct($name, $columns, $indexes) + { + $this->_name = $name; + $this->_columns = $columns; + $this->_indexes = $indexes; + } + + + /*########################################################################## + # Accessor + ##########################################################################*/ + + /** + * @return string + */ + public function getName() + { + return $this->_name; + } + + /** + * @return mixed + */ + public function getPrimaryKey() + { + return $this->_primaryKey; + } + + /** + * @return array + */ + public function getColumns() + { + return $this->_columns; + } + + /** + * @return array + */ + public function getColumnNames() + { + $names = array(); + foreach ($this->_columns as $column) { + $names[] = $column->getName(); + } + return $names; + } + + /** + * @return array + */ + public function getIndexes() + { + return $this->_indexes; + } + + /** + * @return array + */ + public function getIndexNames() + { + $names = array(); + foreach ($this->_indexes as $index) { + $names[] = $index->getName(); + } + return $names; + } + + + /*########################################################################## + # Protected + ##########################################################################*/ + +} diff --git a/framework/Db/package.xml b/framework/Db/package.xml index c3963aaf4..df116acea 100644 --- a/framework/Db/package.xml +++ b/framework/Db/package.xml @@ -43,6 +43,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + @@ -101,6 +102,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> +