From 7f0ca9324b0d70fd36d92653176864c21048fd19 Mon Sep 17 00:00:00 2001 From: Josiah Date: Sat, 13 Oct 2012 16:50:23 +1000 Subject: [PATCH] Added support for multiple config files to be passed to the plovr server --- Command/BaseCommand.php | 31 +++++++++++++++++++++++++++++++ Command/StartPlovrCommand.php | 10 +++++----- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/Command/BaseCommand.php b/Command/BaseCommand.php index 7a6a334..d257470 100644 --- a/Command/BaseCommand.php +++ b/Command/BaseCommand.php @@ -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'); diff --git a/Command/StartPlovrCommand.php b/Command/StartPlovrCommand.php index 304510c..904bdf8 100644 --- a/Command/StartPlovrCommand.php +++ b/Command/StartPlovrCommand.php @@ -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(); @@ -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); } }