From d71f560c0915e3bb162eff7c4f49f36aa8be3f2c Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Mon, 12 May 2014 11:58:43 +0100 Subject: [PATCH] Cleaning up the composer plugin a little --- PHPCI/Plugin/Composer.php | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/PHPCI/Plugin/Composer.php b/PHPCI/Plugin/Composer.php index fdad3bef..8909dbd6 100644 --- a/PHPCI/Plugin/Composer.php +++ b/PHPCI/Plugin/Composer.php @@ -40,12 +40,24 @@ class Composer implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin public function __construct(Builder $phpci, Build $build, array $options = array()) { - $path = $phpci->buildPath; - $this->phpci = $phpci; + $path = $phpci->buildPath; + $this->phpci = $phpci; $this->build = $build; - $this->directory = isset($options['directory']) ? $path . '/' . $options['directory'] : $path; - $this->action = isset($options['action']) ? $options['action'] : 'install'; - $this->preferDist = isset($options['prefer_dist']) ? $options['prefer_dist'] : true; + $this->directory = $path; + $this->action = 'install'; + $this->preferDist = false; + + if (array_key_exists('directory', $options)) { + $this->directory = $path . '/' . $options['directory']; + } + + if (array_key_exists('action', $options)) { + $this->action = $options['action']; + } + + if (array_key_exists('prefer_dist', $options)) { + $this->preferDist = (bool)$options['prefer_dist']; + } } /** @@ -59,12 +71,24 @@ class Composer implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin $this->phpci->logFailure('Could not find Composer.'); return false; } + $cmd = ''; + if (IS_WIN) { $cmd = 'php '; } + $cmd .= $composerLocation . ' --no-ansi --no-interaction '; - $cmd .= ($this->preferDist ? '--prefer-dist' : '--prefer-source') . ' --working-dir="%s" %s'; + + if ($this->preferDist) { + $this->phpci->log('Using --prefer-dist flag'); + $cmd .= '--prefer-dist'; + } else { + $this->phpci->log('Using --prefer-source flag'); + $cmd .= '--prefer-source'; + } + + $cmd .= ' --working-dir="%s" %s'; return $this->phpci->executeCommand($cmd, $this->directory, $this->action); }