Started to integrate the new configuration system (still WIP/dirty)
This commit is contained in:
parent
48b29243f3
commit
09e4da0c19
13 changed files with 53 additions and 413 deletions
|
|
@ -75,11 +75,8 @@ abstract class AbstractCommand extends ContainerAwareCommand
|
|||
// collect all schemas
|
||||
$this->copySchemas($kernel, $this->cacheDir);
|
||||
|
||||
// build.properties
|
||||
$this->createBuildPropertiesFile($kernel, $this->cacheDir.'/build.properties');
|
||||
|
||||
// buildtime-conf.xml
|
||||
$this->createBuildTimeFile($this->cacheDir.'/buildtime-conf.xml');
|
||||
// propel.json
|
||||
$this->createPropelConfigurationFile($this->cacheDir.'/propel.json');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -126,7 +123,7 @@ abstract class AbstractCommand extends ContainerAwareCommand
|
|||
}
|
||||
|
||||
if ($this->input->hasOption('connection')) {
|
||||
$connections = $this->input->getOption('connection') ?: array($this->getContainer()->getParameter('propel.dbal.default_connection'));
|
||||
$connections = $this->input->getOption('connection') ?: array($this->getDefaultConnection());
|
||||
|
||||
if (!in_array((string) $database['name'], $connections)) {
|
||||
// we skip this schema because the connection name doesn't
|
||||
|
|
@ -203,48 +200,15 @@ abstract class AbstractCommand extends ContainerAwareCommand
|
|||
/*
|
||||
* Create an XML file which represents propel.configuration
|
||||
*
|
||||
* @param string $file Should be 'buildtime-conf.xml'.
|
||||
* @param string $file Should be 'propel.json'.
|
||||
*/
|
||||
protected function createBuildTimeFile($file)
|
||||
protected function createPropelConfigurationFile($file)
|
||||
{
|
||||
$xml = strtr(<<<EOT
|
||||
<?xml version="1.0"?>
|
||||
<config>
|
||||
<propel>
|
||||
<datasources default="%default_connection%">
|
||||
$config = array(
|
||||
'propel' => $this->getContainer()->getParameter('propel.configuration')
|
||||
);
|
||||
|
||||
EOT
|
||||
, array('%default_connection%' => $this->getContainer()->getParameter('propel.dbal.default_connection')));
|
||||
|
||||
$datasources = $this->getContainer()->getParameter('propel.configuration');
|
||||
foreach ($datasources as $name => $datasource) {
|
||||
$xml .= strtr(<<<EOT
|
||||
<datasource id="%name%">
|
||||
<adapter>%adapter%</adapter>
|
||||
<connection>
|
||||
<dsn>%dsn%</dsn>
|
||||
<user>%username%</user>
|
||||
<password>%password%</password>
|
||||
</connection>
|
||||
</datasource>
|
||||
|
||||
EOT
|
||||
, array(
|
||||
'%name%' => $name,
|
||||
'%adapter%' => $datasource['adapter'],
|
||||
'%dsn%' => $datasource['connection']['dsn'],
|
||||
'%username%' => $datasource['connection']['user'],
|
||||
'%password%' => isset($datasource['connection']['password']) ? $datasource['connection']['password'] : '',
|
||||
));
|
||||
}
|
||||
|
||||
$xml .= <<<EOT
|
||||
</datasources>
|
||||
</propel>
|
||||
</config>
|
||||
EOT;
|
||||
|
||||
file_put_contents($file, $xml);
|
||||
file_put_contents($file, json_encode($config, JSON_PRETTY_PRINT));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -274,11 +238,11 @@ EOT;
|
|||
protected function getConnectionData($name)
|
||||
{
|
||||
$knownConnections = $this->getContainer()->getParameter('propel.configuration');
|
||||
if (!isset($knownConnections[$name])) {
|
||||
if (!isset($knownConnections['database']['connections'][$name])) {
|
||||
throw new \InvalidArgumentException(sprintf('Unknown connection "%s"', $name));
|
||||
}
|
||||
|
||||
return $knownConnections[$name];
|
||||
return $knownConnections['database']['connections'][$name];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -291,32 +255,8 @@ EOT;
|
|||
protected function getDsn($connectionName)
|
||||
{
|
||||
$connection = $this->getConnectionData($connectionName);
|
||||
$connectionData = $connection['connection'];
|
||||
|
||||
return sprintf('%s;user=%s;password=%s', $connectionData['dsn'], $connectionData['user'], $connectionData['password']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a 'build.properties' file.
|
||||
*
|
||||
* @param KernelInterface $kernel The application kernel.
|
||||
* @param string $file Should be 'build.properties'.
|
||||
*/
|
||||
protected function createBuildPropertiesFile(KernelInterface $kernel, $file)
|
||||
{
|
||||
$fs = new Filesystem();
|
||||
|
||||
$buildProperties = $this->getContainer()->getParameter('propel.build_properties');
|
||||
$iniFile = $kernel->getRootDir().'/config/propel.ini';
|
||||
|
||||
if ($fs->exists($iniFile)) {
|
||||
$buildProperties = array_merge(
|
||||
parse_ini_file($iniFile),
|
||||
$buildProperties
|
||||
);
|
||||
}
|
||||
|
||||
$fs->dumpFile($file, $this->arrayToIni($buildProperties));
|
||||
return $connection['dsn'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -374,24 +314,6 @@ EOT;
|
|||
return $this->cacheDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array to its INI equivalent
|
||||
*
|
||||
* @param array $data The array to convert.
|
||||
*
|
||||
* @return string The INI formatted array.
|
||||
*/
|
||||
protected function arrayToIni(array $data)
|
||||
{
|
||||
$lines = array();
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
$lines[] = $key . ' =' . (!empty($value) ? ' ' . $value : '');
|
||||
}
|
||||
|
||||
return implode(PHP_EOL, $lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the database name from a given DSN
|
||||
*
|
||||
|
|
@ -409,4 +331,16 @@ EOT;
|
|||
// e.g. SQLite
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the default connection.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDefaultConnection()
|
||||
{
|
||||
$config = $this->getContainer()->getParameter('propel.configuration');
|
||||
|
||||
return $config['generator']['defaultConnection'];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,9 +44,9 @@ class DatabaseCreateCommand extends AbstractCommand
|
|||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$connectionName = $input->getOption('connection') ?: $this->getContainer()->getParameter('propel.dbal.default_connection');
|
||||
$connectionName = $input->getOption('connection') ?: $this->getDefaultConnection();
|
||||
$config = $this->getConnectionData($connectionName);
|
||||
$dbName = $this->parseDbName($config['connection']['dsn']);
|
||||
$dbName = $this->parseDbName($config['dsn']);
|
||||
|
||||
if (null === $dbName) {
|
||||
return $output->writeln('<error>No database name found.</error>');
|
||||
|
|
@ -56,7 +56,7 @@ class DatabaseCreateCommand extends AbstractCommand
|
|||
|
||||
try {
|
||||
$manager = new ConnectionManagerSingle();
|
||||
$manager->setConfiguration($this->getTemporaryConfiguration($config['connection']));
|
||||
$manager->setConfiguration($this->getTemporaryConfiguration($config));
|
||||
|
||||
$serviceContainer = Propel::getServiceContainer();
|
||||
$serviceContainer->setAdapterClass($connectionName, $config['adapter']);
|
||||
|
|
|
|||
|
|
@ -68,10 +68,10 @@ EOT
|
|||
}
|
||||
}
|
||||
|
||||
$connectionName = $input->getOption('connection') ?: $this->getContainer()->getParameter('propel.dbal.default_connection');
|
||||
$connectionName = $input->getOption('connection') ?: $this->getDefaultConnection();
|
||||
$config = $this->getConnectionData($connectionName);
|
||||
$connection = Propel::getConnection($connectionName);
|
||||
$dbName = $this->parseDbName($config['connection']['dsn']);
|
||||
$dbName = $this->parseDbName($config['dsn']);
|
||||
|
||||
if (null === $dbName) {
|
||||
return $output->writeln('<error>No database name found.</error>');
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ namespace Propel\PropelBundle\Command;
|
|||
|
||||
use Propel\Generator\Config\GeneratorConfig;
|
||||
use Propel\Generator\Command\ModelBuildCommand as BaseModelBuildCommand;
|
||||
use Propel\Generator\Command\AbstractCommand as BaseCommand;
|
||||
use Propel\Generator\Model\Database;
|
||||
use Propel\Generator\Model\Table;
|
||||
use Propel\Generator\Manager\ModelManager;
|
||||
|
|
@ -42,7 +41,7 @@ class FormGenerateCommand extends AbstractCommand
|
|||
->setDescription('Generate Form types stubs based on the schema.xml')
|
||||
|
||||
->addOption('force', 'f', InputOption::VALUE_NONE, 'Overwrite existing Form types')
|
||||
->addOption('platform', null, InputOption::VALUE_REQUIRED, 'The platform', BaseCommand::DEFAULT_PLATFORM)
|
||||
->addOption('platform', null, InputOption::VALUE_REQUIRED, 'The platform')
|
||||
->addArgument('bundle', InputArgument::REQUIRED, 'The bundle to use to generate Form types (Ex: @AcmeDemoBundle)')
|
||||
->addArgument('models', InputArgument::IS_ARRAY, 'Model classes to generate Form Types from')
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class MigrationDiffCommand extends WrappedCommand
|
|||
|
||||
->addOption('connection', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'Connection to use. Example: default, bookstore')
|
||||
->addOption('output-dir', null, InputOption::VALUE_OPTIONAL, 'The output directory')
|
||||
->addOption('migration-table', null, InputOption::VALUE_REQUIRED, 'Migration table name', BaseMigrationCommand::DEFAULT_MIGRATION_TABLE)
|
||||
->addOption('migration-table', null, InputOption::VALUE_REQUIRED, 'Migration table name', null)
|
||||
->addOption('table-renaming', null, InputOption::VALUE_NONE, 'Detect table renaming', null)
|
||||
->addOption('editor', null, InputOption::VALUE_OPTIONAL, 'The text editor to use to open diff files', null)
|
||||
->addOption('skip-removed-table', null, InputOption::VALUE_NONE, 'Option to skip removed table from the migration')
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class SqlInsertCommand extends WrappedCommand
|
|||
{
|
||||
return array(
|
||||
'--connection' => $this->getConnections($input->getOption('connection')),
|
||||
'--sql-dir' => $this->cacheDir,
|
||||
'--sql-dir' => $this->cacheDir,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@
|
|||
|
||||
namespace Propel\PropelBundle\Command;
|
||||
|
||||
use Propel\Generator\Command\AbstractCommand as BaseCommand;
|
||||
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
|
@ -41,7 +39,7 @@ abstract class WrappedCommand extends AbstractCommand
|
|||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->addOption('platform', null, InputOption::VALUE_REQUIRED, 'The platform', BaseCommand::DEFAULT_PLATFORM)
|
||||
->addOption('platform', null, InputOption::VALUE_OPTIONAL, 'The platform')
|
||||
;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue