From 6ab7973fd2232e89ed707bb03a48fa1baf953692 Mon Sep 17 00:00:00 2001 From: Marc Aschmann Date: Wed, 6 Aug 2014 17:46:19 +0200 Subject: [PATCH] Make PHPCI output properly formatted JSON and Yaml files where possible, rather than one-line files. Closes #547 --- PHPCI/Command/InstallCommand.php | 2 +- PHPCI/Controller/PluginController.php | 12 +++++++++++- PHPCI/Controller/SettingsController.php | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/PHPCI/Command/InstallCommand.php b/PHPCI/Command/InstallCommand.php index e24fe2f3..a4a0c4bb 100644 --- a/PHPCI/Command/InstallCommand.php +++ b/PHPCI/Command/InstallCommand.php @@ -312,7 +312,7 @@ class InstallCommand extends Command protected function writeConfigFile(array $config) { $dumper = new \Symfony\Component\Yaml\Dumper(); - $yaml = $dumper->dump($config, 2); + $yaml = $dumper->dump($config, 4); file_put_contents($this->configFilePath, $yaml); } diff --git a/PHPCI/Controller/PluginController.php b/PHPCI/Controller/PluginController.php index 5cbb662d..777c846f 100644 --- a/PHPCI/Controller/PluginController.php +++ b/PHPCI/Controller/PluginController.php @@ -109,9 +109,19 @@ class PluginController extends \PHPCI\Controller return json_decode($json, true); } + /** + * Convert array to json and save composer.json + * + * @param $array + */ protected function setComposerJson($array) { - $json = json_encode($array); + if (defined('JSON_PRETTY_PRINT')) { + $json = json_encode($array, JSON_PRETTY_PRINT); + } else { + $json = json_encode($array); + } + file_put_contents(APPLICATION_PATH . 'composer.json', $json); } diff --git a/PHPCI/Controller/SettingsController.php b/PHPCI/Controller/SettingsController.php index bc5558ba..0bb79577 100644 --- a/PHPCI/Controller/SettingsController.php +++ b/PHPCI/Controller/SettingsController.php @@ -138,11 +138,16 @@ class SettingsController extends Controller die; } + /** + * Convert config to yaml and store to file. + * @return mixed + */ protected function storeSettings() { $dumper = new Dumper(); - $yaml = $dumper->dump($this->settings); + $yaml = $dumper->dump($this->settings, 4); file_put_contents(APPLICATION_PATH . 'PHPCI/config.yml', $yaml); + if (error_get_last()) { $error_get_last = error_get_last(); return $error_get_last['message'];