add initial Table object for retrieving schema info in one object
authorChuck Hagenbuch <chuck@horde.org>
Sat, 10 Jan 2009 16:11:23 +0000 (11:11 -0500)
committerChuck Hagenbuch <chuck@horde.org>
Sat, 10 Jan 2009 16:11:23 +0000 (11:11 -0500)
framework/Db/lib/Horde/Db/Adapter/Abstract/Schema.php
framework/Db/lib/Horde/Db/Adapter/Abstract/Table.php [new file with mode: 0644]
framework/Db/package.xml

index 58599c9..edf7100 100644 (file)
@@ -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 (file)
index 0000000..f948e29
--- /dev/null
@@ -0,0 +1,114 @@
+<?php
+/**
+ * Copyright 2007 Maintainable Software, LLC
+ * Copyright 2008 The Horde Project (http://www.horde.org/)
+ *
+ * @author     Mike Naberezny <mike@maintainable.com>
+ * @author     Derek DeVries <derek@maintainable.com>
+ * @author     Chuck Hagenbuch <chuck@horde.org>
+ * @license    http://opensource.org/licenses/bsd-license.php
+ * @category   Horde
+ * @package    Horde_Db
+ * @subpackage Adapter
+ */
+
+/**
+ * @author     Mike Naberezny <mike@maintainable.com>
+ * @author     Derek DeVries <derek@maintainable.com>
+ * @author     Chuck Hagenbuch <chuck@horde.org>
+ * @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 <tt>supplier_id</tt> in <tt>supplier_id int(11)</tt>.
+     */
+    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
+    ##########################################################################*/
+
+}
index c3963aa..df116ac 100644 (file)
@@ -43,6 +43,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
         <file name="ColumnDefinition.php" role="php" />
         <file name="Index.php" role="php" />
         <file name="Schema.php" role="php" />
+        <file name="Table.php" role="php" />
         <file name="TableDefinition.php" role="php" />
        </dir> <!-- /lib/Horde/Db/Adapter/Abstract -->
        <dir name="Mssql">
@@ -101,6 +102,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
    <install name="lib/Horde/Db/Adapter/Abstract/ColumnDefinition.php" as="Horde/Db/Adapter/Abstract/ColumnDefinition.php" />
    <install name="lib/Horde/Db/Adapter/Abstract/Index.php" as="Horde/Db/Adapter/Abstract/Index.php" />
    <install name="lib/Horde/Db/Adapter/Abstract/Schema.php" as="Horde/Db/Adapter/Abstract/Schema.php" />
+   <install name="lib/Horde/Db/Adapter/Abstract/Table.php" as="Horde/Db/Adapter/Abstract/Table.php" />
    <install name="lib/Horde/Db/Adapter/Abstract/TableDefinition.php" as="Horde/Db/Adapter/Abstract/TableDefinition.php" />
    <install name="lib/Horde/Db/Adapter/Abstract.php" as="Horde/Db/Adapter/Abstract.php" />