Doctrine 1.2.4
Doctrine_Import Class Reference

Inherits Doctrine_Connection_Module.

Inherited by Doctrine_Import_Mssql, Doctrine_Import_Mysql, Doctrine_Import_Oracle, Doctrine_Import_Pgsql, and Doctrine_Import_Sqlite.

Public Member Functions

 databaseExists ($database)
 
 functionExists ($function)
 
 getConnection ()
 
 getModuleName ()
 
 importSchema ($directory, array $connections=array(), array $options=array())
 
 listDatabases ()
 
 listFunctions ()
 
 listSequences ($database=null)
 
 listTableColumns ($table)
 
 listTableConstraints ($table)
 
 listTableIndexes ($table)
 
 listTableRelations ($table)
 
 listTables ($database=null)
 
 listTableTriggers ($table)
 
 listTableViews ($table)
 
 listTriggers ($database=null)
 
 listUsers ()
 
 listViews ($database=null)
 
 sequenceExists ($sequence, $database=null)
 
 tableColumnExists ($column, $table)
 
 tableConstraintExists ($constraint, $table)
 
 tableExists ($table, $database=null)
 
 tableIndexExists ($index, $table)
 
 tableTriggerExists ($trigger, $table)
 
 tableViewExists ($view, $table)
 
 triggerExists ($trigger, $database=null)
 
 userExists ($user)
 
 viewExists ($view, $database=null)
 

Detailed Description

Definition at line 37 of file Import.php.

Member Function Documentation

Doctrine_Import::databaseExists (   $database)

checks if a database exists

Parameters
string$database
Returns
boolean

Definition at line 220 of file Import.php.

{
return in_array($database, $this->listDatabases());
}
Doctrine_Import::functionExists (   $function)

checks if a function exists

Parameters
string$function
Returns
boolean

Definition at line 231 of file Import.php.

{
return in_array($function, $this->listFunctions());
}
Doctrine_Connection_Module::getConnection ( )
inherited

getConnection returns the connection object this module uses

Returns
Doctrine_Connection

Definition at line 68 of file Module.php.

{
return $this->conn;
}
Doctrine_Connection_Module::getModuleName ( )
inherited

getModuleName returns the name of this module

Returns
string the name of this module

Definition at line 79 of file Module.php.

{
return $this->moduleName;
}
Doctrine_Import::importSchema (   $directory,
array  $connections = array(),
array  $options = array() 
)

importSchema

method for importing existing schema to Doctrine_Record classes

Parameters
string$directory
array$connectionsArray of connection names to generate models for
Returns
array the names of the imported classes

Definition at line 364 of file Import.php.

{
$classes = array();
foreach ($manager as $name => $connection) {
// Limit the databases to the ones specified by $connections.
// Check only happens if array is not empty
if ( ! empty($connections) && ! in_array($name, $connections)) {
continue;
}
$builder = new Doctrine_Import_Builder();
$builder->setTargetPath($directory);
$builder->setOptions($options);
$definitions = array();
foreach ($connection->import->listTables() as $table) {
$definition = array();
$definition['tableName'] = $table;
$definition['className'] = Doctrine_Inflector::classify(Doctrine_Inflector::tableize($table));
$definition['columns'] = $connection->import->listTableColumns($table);
$definition['connection'] = $connection->getName();
$definition['connectionClassName'] = $definition['className'];
try {
$definition['relations'] = array();
$relations = $connection->import->listTableRelations($table);
$relClasses = array();
foreach ($relations as $relation) {
$table = $relation['table'];
if (in_array($class, $relClasses)) {
$alias = $class . '_' . (count($relClasses) + 1);
} else {
$alias = $class;
}
$relClasses[] = $class;
$definition['relations'][$alias] = array(
'alias' => $alias,
'class' => $class,
'local' => $relation['local'],
'foreign' => $relation['foreign']
);
}
} catch (Exception $e) {}
$definitions[strtolower($definition['className'])] = $definition;
$classes[] = $definition['className'];
}
// Build opposite end of relationships
foreach ($definitions as $definition) {
$className = $definition['className'];
$relClasses = array();
foreach ($definition['relations'] as $alias => $relation) {
if (in_array($relation['class'], $relClasses) || isset($definitions[$relation['class']]['relations'][$className])) {
$alias = $className . '_' . (count($relClasses) + 1);
} else {
$alias = $className;
}
$relClasses[] = $relation['class'];
$definitions[strtolower($relation['class'])]['relations'][$alias] = array(
'alias' => $alias,
'class' => $className,
'local' => $relation['foreign'],
'foreign' => $relation['local']
);
}
}
// Build records
foreach ($definitions as $definition) {
$builder->buildRecord($definition);
}
}
return $classes;
}
Doctrine_Import::listDatabases ( )

lists all databases

Returns
array

Definition at line 46 of file Import.php.

{
if ( ! isset($this->sql['listDatabases'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
return $this->conn->fetchColumn($this->sql['listDatabases']);
}
Doctrine_Import::listFunctions ( )

lists all availible database functions

Returns
array

Definition at line 60 of file Import.php.

{
if ( ! isset($this->sql['listFunctions'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
return $this->conn->fetchColumn($this->sql['listFunctions']);
}
Doctrine_Import::listSequences (   $database = null)

lists all database sequences

Parameters
string | null$database
Returns
array

Definition at line 86 of file Import.php.

{
if ( ! isset($this->sql['listSequences'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
return $this->conn->fetchColumn($this->sql['listSequences']);
}
Doctrine_Import::listTableColumns (   $table)

lists table constraints

Parameters
string$tabledatabase table name
Returns
array

Definition at line 136 of file Import.php.

{
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
Doctrine_Import::listTableConstraints (   $table)

lists table constraints

Parameters
string$tabledatabase table name
Returns
array

Definition at line 101 of file Import.php.

{
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
Doctrine_Import::listTableIndexes (   $table)

lists table constraints

Parameters
string$tabledatabase table name
Returns
array

Definition at line 147 of file Import.php.

{
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
Doctrine_Import::listTableRelations (   $table)

lists table relations

Expects an array of this format to be returned with all the relationships in it where the key is the name of the foreign table, and the value is an array containing the local and foreign column name

Array ( [groups] => Array ( [local] => group_id [foreign] => id ) )

Parameters
string$tabledatabase table name
Returns
array

Definition at line 125 of file Import.php.

{
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
Doctrine_Import::listTables (   $database = null)

lists tables

Parameters
string | null$database
Returns
array

Definition at line 158 of file Import.php.

{
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
Doctrine_Import::listTableTriggers (   $table)

lists table triggers

Parameters
string$tabledatabase table name
Returns
array

Definition at line 169 of file Import.php.

{
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
Doctrine_Import::listTableViews (   $table)

lists table views

Parameters
string$tabledatabase table name
Returns
array

Definition at line 180 of file Import.php.

{
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
Doctrine_Import::listTriggers (   $database = null)

lists all database triggers

Parameters
string | null$database
Returns
array

Definition at line 75 of file Import.php.

{
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
Doctrine_Import::listUsers ( )

lists database users

Returns
array

Definition at line 190 of file Import.php.

{
if ( ! isset($this->sql['listUsers'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
return $this->conn->fetchColumn($this->sql['listUsers']);
}
Doctrine_Import::listViews (   $database = null)

lists database views

Parameters
string | null$database
Returns
array

Definition at line 205 of file Import.php.

{
if ( ! isset($this->sql['listViews'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
return $this->conn->fetchColumn($this->sql['listViews']);
}
Doctrine_Import::sequenceExists (   $sequence,
  $database = null 
)

checks if a sequence exists

Parameters
string$sequence
string | null$database
Returns
boolean

Definition at line 255 of file Import.php.

{
return in_array($sequence, $this->listSequences($database));
}
Doctrine_Import::tableColumnExists (   $column,
  $table 
)

checks if a table column exists

Parameters
string$column
string$tabledatabase table name
Returns
boolean

Definition at line 279 of file Import.php.

{
return in_array($column, $this->listTableColumns($table));
}
Doctrine_Import::tableConstraintExists (   $constraint,
  $table 
)

checks if a table constraint exists

Parameters
string$constraint
string$tabledatabase table name
Returns
boolean

Definition at line 267 of file Import.php.

{
return in_array($constraint, $this->listTableConstraints($table));
}
Doctrine_Import::tableExists (   $table,
  $database = null 
)

checks if a table exists

Parameters
string$table
string | null$database
Returns
boolean

Definition at line 303 of file Import.php.

{
return in_array($table, $this->listTables($database));
}
Doctrine_Import::tableIndexExists (   $index,
  $table 
)

checks if a table index exists

Parameters
string$index
string$tabledatabase table name
Returns
boolean

Definition at line 291 of file Import.php.

{
return in_array($index, $this->listTableIndexes($table));
}
Doctrine_Import::tableTriggerExists (   $trigger,
  $table 
)

checks if a table trigger exists

Parameters
string$trigger
string$tabledatabase table name
Returns
boolean

Definition at line 315 of file Import.php.

{
return in_array($trigger, $this->listTableTriggers($table));
}
Doctrine_Import::tableViewExists (   $view,
  $table 
)

checks if a table view exists

Parameters
string$view
string$tabledatabase table name
Returns
boolean

Definition at line 327 of file Import.php.

{
return in_array($view, $this->listTableViews($table));
}
Doctrine_Import::triggerExists (   $trigger,
  $database = null 
)

checks if a trigger exists

Parameters
string$trigger
string | null$database
Returns
boolean

Definition at line 243 of file Import.php.

{
return in_array($trigger, $this->listTriggers($database));
}
Doctrine_Import::userExists (   $user)

checks if a user exists

Parameters
string$user
Returns
boolean

Definition at line 338 of file Import.php.

{
return in_array($user, $this->listUsers());
}
Doctrine_Import::viewExists (   $view,
  $database = null 
)

checks if a view exists

Parameters
string$view
string | null$database
Returns
boolean

Definition at line 350 of file Import.php.

{
return in_array($view, $this->listViews($database));
}

The documentation for this class was generated from the following file: