/*##########################################################################
+ # Object factory
+ ##########################################################################*/
+
+ /**
+ * Delegate calls to the schema object.
+ *
+ * @param string $method
+ * @param array $args
+ */
+ public function componentFactory($component, $args)
+ {
+ $class = str_replace('_Schema', '', $this->_schemaClass) . '_' . $component;
+ if (class_exists($class)) {
+ $class = new ReflectionClass($class);
+ } else {
+ $class = new ReflectionClass('Horde_Db_Adapter_Abstract_' . $component);
+ }
+
+ return $class->newInstanceArgs($args);
+ }
+
+
+ /*##########################################################################
# Object composition
##########################################################################*/
*/
public function createTable($name, $options=array())
{
- $pk = isset($options['primaryKey']) &&
- $options['primaryKey'] === false ? false : 'id';
+ $pk = isset($options['primaryKey']) && $options['primaryKey'] === false ? false : 'id';
$tableDefinition =
- new Horde_Db_Adapter_Abstract_TableDefinition($name, $this, $options);
+ $this->componentFactory('TableDefinition', array($name, $this, $options));
if ($pk != false) {
$tableDefinition->primaryKey($pk);
}
* @param string $table
* @return string
*/
- abstract public function structureDump($table=null);
+ abstract public function structureDump($table = null);
/**
* Recreate the given db
if ($this[$name]) {
$column = $this[$name];
} else {
- $column = new Horde_Db_Adapter_Abstract_ColumnDefinition(
- $this->_base, $name, $type);
+ $column = $this->_base->componentFactory('ColumnDefinition', array(
+ $this->_base, $name, $type));
}
$natives = $this->_native();
// create columns from rows
$columns = array();
foreach ($rows as $row) {
- $columns[] = new Horde_Db_Adapter_Mysql_Column(
- $row[0], $row[4], $row[1], $row[2] == 'YES');
+ $columns[] = $this->componentFactory('Column', array(
+ $row[0], $row[4], $row[1], $row[2] == 'YES'));
}
return $columns;
}
/**
- * Override createTable to return a Mysql Table Definition
- * param string $name
- * param array $options
- */
- public function createTable($name, $options=array())
- {
- $pk = isset($options['primaryKey']) && $options['primaryKey'] === false ? false : 'id';
- $tableDefinition =
- new Horde_Db_Adapter_Mysql_TableDefinition($name, $this, $options);
- if ($pk != false) {
- $tableDefinition->primaryKey($pk);
- }
- return $tableDefinition;
- }
-
- /**
* @param string $name
* @param array $options
*/
// create columns from rows
$columns = array();
foreach ($rows as $row) {
- $columns[] = new Horde_Db_Adapter_Postgresql_Column(
- $row[0], $row[2], $row[1], !(boolean)$row[3]);
+ $columns[] = $this->componentFactory('Column', array(
+ $row[0], $row[2], $row[1], !(boolean)$row[3]));
}
return $columns;
}
// create columns from rows
$columns = array();
foreach ($rows as $row) {
- $columns[] = new Horde_Db_Adapter_Sqlite_Column(
- $row[1], $row[4], $row[2], !(bool)$row[3]);
+ $columns[] = $this->componentFactory('Column', array(
+ $row[1], $row[4], $row[2], !(bool)$row[3]));
}
return $columns;
}
/**
- * Override createTable to return a Sqlite Table Definition
- * param string $name
- * param array $options
- */
- public function createTable($name, $options=array())
- {
- $pk = isset($options['primaryKey']) && $options['primaryKey'] === false ? false : 'id';
- $tableDefinition =
- new Horde_Db_Adapter_Abstract_TableDefinition($name, $this, $options);
- if ($pk != false) {
- $tableDefinition->primaryKey($pk);
- }
- return $tableDefinition;
- }
-
- /**
* @param string $name
* @param string $newName
*/