[PropelBundle] Added auto package based on namespace

This commit is contained in:
Francois Zaninotto 2010-06-15 18:47:02 +02:00 committed by Fabien Potencier
parent 82d83fc6c9
commit 3ec25777d1
2 changed files with 22 additions and 10 deletions

View File

@ -54,13 +54,24 @@ abstract class PhingCommand extends Command
$file = $tmpDir.DIRECTORY_SEPARATOR.$tempSchema;
$filesystem->copy((string) $schema, $file);
$content = file_get_contents($file);
$content = preg_replace_callback('/package\s*=\s*"(.*?)"/', function ($matches) use ($prefix) {
$package = $prefix.'.'.$matches[1];
return sprintf('package="%s"', $package);
}, $content);
file_put_contents($file, $content);
// the package needs to be set absolute
// besides, the automated namespace to package conversion has not taken place yet
// so it needs to be done manually
$database = simplexml_load_file($file);
if (isset($database['package'])) {
$database['package'] = $prefix . '.' . $database['package'];
} elseif (isset($database['namespace'])) {
$database['package'] = $prefix . '.' . str_replace('\\', '.', $database['namespace']);
}
foreach ($database->table as $table)
{
if (isset($table['package'])) {
$table['package'] = $prefix . '.' . $table['package'];
} elseif (isset($table['namespace'])) {
$table['package'] = $prefix . '.' . str_replace('\\', '.', $table['namespace']);
}
}
file_put_contents($file, $database->asXML());
}
}
}
@ -75,6 +86,7 @@ abstract class PhingCommand extends Command
'project.dir' => $tmpDir,
'propel.output.dir' => $kernel->getRootDir().'/propel',
'propel.php.dir' => '/',
'propel.packageObjectModel' => true,
), $properties);
foreach ($properties as $key => $value) {
$args[] = "-D$key=$value";

View File

@ -48,9 +48,9 @@ Sample Configuration
Place the following schema in src/Application/HelloBundle/Resources/config/schema.xml:
<?xml version="1.0" encoding="UTF-8"?>
<database name="default" package="Application.HelloBundle.Model" defaultIdMethod="native">
<database name="default" namespace="Application\HelloBundle\Model" defaultIdMethod="native">
<table name="book" namespace="Application\HelloBundle\Model">
<table name="book">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
<column name="title" type="varchar" primaryString="1" size="100" />
<column name="ISBN" type="varchar" size="20" />
@ -60,7 +60,7 @@ Place the following schema in src/Application/HelloBundle/Resources/config/schem
</foreign-key>
</table>
<table name="author" namespace="Application\HelloBundle\Model">
<table name="author">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
<column name="first_name" type="varchar" size="100" />
<column name="last_name" type="varchar" size="100" />