1
0
mirror of synced 2024-12-13 14:56:01 +03:00

DDC-1179 - Make it possible to specify a namespace when mapping with --from-database

This commit is contained in:
Alexander 2011-06-02 21:45:03 +02:00
parent cec62db2d8
commit 7ee8dc4e44
2 changed files with 34 additions and 6 deletions

View File

@ -66,6 +66,13 @@ class DatabaseDriver implements Driver
*/
private $fieldNamesForColumns = array();
/**
* The namespace for the generated entities.
*
* @var string
*/
private $namespace;
/**
* Initializes a new AnnotationDriver that uses the given AnnotationReader for reading
* docblock annotations.
@ -348,10 +355,10 @@ class DatabaseDriver implements Driver
private function getClassNameForTable($tableName)
{
if (isset($this->classNamesForTables[$tableName])) {
return $this->classNamesForTables[$tableName];
return $this->namespace . $this->classNamesForTables[$tableName];
}
return Inflector::classify(strtolower($tableName));
return $this->namespace . Inflector::classify(strtolower($tableName));
}
/**
@ -376,4 +383,15 @@ class DatabaseDriver implements Driver
}
return Inflector::camelize($columnName);
}
/**
* Set the namespace for the generated entities.
*
* @param string $namespace
* @return void
*/
public function setNamespace($namespace)
{
$this->namespace = $namespace;
}
}

View File

@ -78,6 +78,10 @@ class ConvertMappingCommand extends Console\Command\Command
'num-spaces', null, InputOption::VALUE_OPTIONAL,
'Defines the number of indentation spaces', 4
),
new InputOption(
'namespace', null, InputOption::VALUE_OPTIONAL,
'Defines a namespace for the generated entity classes, if converted from database.'
),
))
->setHelp(<<<EOT
Convert mapping information between supported formats.
@ -107,11 +111,17 @@ EOT
$em = $this->getHelper('em')->getEntityManager();
if ($input->getOption('from-database') === true) {
$em->getConfiguration()->setMetadataDriverImpl(
new \Doctrine\ORM\Mapping\Driver\DatabaseDriver(
$em->getConnection()->getSchemaManager()
)
$databaseDriver = new \Doctrine\ORM\Mapping\Driver\DatabaseDriver(
$em->getConnection()->getSchemaManager()
);
$em->getConfiguration()->setMetadataDriverImpl(
$databaseDriver
);
if (($namespace = $input->getOption('namespace')) !== null) {
$databaseDriver->setNamespace($namespace);
}
}
$cmf = new DisconnectedClassMetadataFactory();