Skip to content

Commit

Permalink
Added support for multiple config files to be passed to the plovr server
Browse files Browse the repository at this point in the history
  • Loading branch information
Josiah committed Oct 13, 2012
1 parent a0c2138 commit 7f0ca93
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
31 changes: 31 additions & 0 deletions Command/BaseCommand.php
Expand Up @@ -65,6 +65,37 @@ protected function loadPlovrConfig($file)
return $config;
}

/**
* Processes the plover config and generates a list of configuration files
* which can be safely passed to the plovr command line.
*
* @param array $files Files
* @return array
*/
protected function processPlovrConfig($configs)
{
$configPaths = array();

foreach ($configs as $inputConfig) {
$config = $this->loadPlovrConfig($inputConfig);
$configPaths[] = $this->writeTempConfig($config);
}

return $configPaths;
}

/**
* Cleans up the config files gnerated in the running of the command
*
* @param array $files Files to cleanup
*/
protected function cleanupPlovrConfig($files)
{
foreach ($files as $file) {
unlink($file);
}
}

protected function locateJavaBin(InputInterface $input)
{
$javaBin = $input->getOption('java-bin');
Expand Down
10 changes: 5 additions & 5 deletions Command/StartPlovrCommand.php
Expand Up @@ -34,7 +34,7 @@ protected function configure()
$this
->setName('plovr:start')
->setDescription('Starts the Plovr server')
->addArgument('config', InputArgument::REQUIRED, 'The configuration file to use')
->addArgument('config', InputArgument::IS_ARRAY, 'The configuration file(s) to use')
;

parent::configure();
Expand All @@ -44,10 +44,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$javaBin = $this->locateJavaBin($input);
$plovrJar = $this->locatePlovrJar($input);
$config = $this->loadPlovrConfig($input->getArgument('config'));
$path = $this->writeTempConfig($config);
$configPaths = $this->processPlovrConfig($input->getArgument('config'));

$this->runJar($output, $javaBin, $plovrJar, 'serve '.escapeshellarg($path));
unlink($path);
$this->runJar($output, $javaBin, $plovrJar, 'serve '.implode(' ', array_map('escapeshellarg', $configPaths)));

$this->cleanupPloverConfig($configPaths);
}
}

0 comments on commit 7f0ca93

Please sign in to comment.