[PropelBundle] Added auto package based on namespace
This commit is contained in:
parent
82d83fc6c9
commit
3ec25777d1
@ -54,13 +54,24 @@ abstract class PhingCommand extends Command
|
|||||||
$file = $tmpDir.DIRECTORY_SEPARATOR.$tempSchema;
|
$file = $tmpDir.DIRECTORY_SEPARATOR.$tempSchema;
|
||||||
$filesystem->copy((string) $schema, $file);
|
$filesystem->copy((string) $schema, $file);
|
||||||
|
|
||||||
$content = file_get_contents($file);
|
// the package needs to be set absolute
|
||||||
$content = preg_replace_callback('/package\s*=\s*"(.*?)"/', function ($matches) use ($prefix) {
|
// besides, the automated namespace to package conversion has not taken place yet
|
||||||
$package = $prefix.'.'.$matches[1];
|
// so it needs to be done manually
|
||||||
return sprintf('package="%s"', $package);
|
$database = simplexml_load_file($file);
|
||||||
}, $content);
|
if (isset($database['package'])) {
|
||||||
|
$database['package'] = $prefix . '.' . $database['package'];
|
||||||
file_put_contents($file, $content);
|
} 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,
|
'project.dir' => $tmpDir,
|
||||||
'propel.output.dir' => $kernel->getRootDir().'/propel',
|
'propel.output.dir' => $kernel->getRootDir().'/propel',
|
||||||
'propel.php.dir' => '/',
|
'propel.php.dir' => '/',
|
||||||
|
'propel.packageObjectModel' => true,
|
||||||
), $properties);
|
), $properties);
|
||||||
foreach ($properties as $key => $value) {
|
foreach ($properties as $key => $value) {
|
||||||
$args[] = "-D$key=$value";
|
$args[] = "-D$key=$value";
|
||||||
|
@ -48,9 +48,9 @@ Sample Configuration
|
|||||||
Place the following schema in src/Application/HelloBundle/Resources/config/schema.xml:
|
Place the following schema in src/Application/HelloBundle/Resources/config/schema.xml:
|
||||||
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
|
||||||
<column name="title" type="varchar" primaryString="1" size="100" />
|
<column name="title" type="varchar" primaryString="1" size="100" />
|
||||||
<column name="ISBN" type="varchar" size="20" />
|
<column name="ISBN" type="varchar" size="20" />
|
||||||
@ -60,7 +60,7 @@ Place the following schema in src/Application/HelloBundle/Resources/config/schem
|
|||||||
</foreign-key>
|
</foreign-key>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<table name="author" namespace="Application\HelloBundle\Model">
|
<table name="author">
|
||||||
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
|
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
|
||||||
<column name="first_name" type="varchar" size="100" />
|
<column name="first_name" type="varchar" size="100" />
|
||||||
<column name="last_name" type="varchar" size="100" />
|
<column name="last_name" type="varchar" size="100" />
|
||||||
|
Reference in New Issue
Block a user