From f7e466bdb11826c75a4a7d0b76090b6f8dcdd722 Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Tue, 8 Oct 2013 08:30:15 +0100 Subject: [PATCH] Fixes #147 --- PHPCI/Plugin/Composer.php | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/PHPCI/Plugin/Composer.php b/PHPCI/Plugin/Composer.php index 36357986..08060f83 100644 --- a/PHPCI/Plugin/Composer.php +++ b/PHPCI/Plugin/Composer.php @@ -36,7 +36,36 @@ class Composer implements \PHPCI\Plugin */ public function execute() { - $cmd = PHPCI_DIR . 'composer.phar --no-ansi --no-interaction '. ($this->preferDist ? '--prefer-dist' : null) .' --working-dir="%s" %s'; + $composerLocation = $this->whereIsComposer(); + + if (!$composerLocation) { + $this->phpci->logFailure('Could not find Composer.'); + return false; + } + + $cmd = $composerLocation . ' --no-ansi --no-interaction '. ($this->preferDist ? '--prefer-dist' : null) .' --working-dir="%s" %s'; + return $this->phpci->executeCommand($cmd, $this->directory, $this->action); } + + protected function whereIsComposer() + { + if (is_file(PHPCI_DIR . 'composer.phar')) { + return PHPCI_DIR . 'composer.phar'; + } + + $which = trim(shell_exec('which composer')); + + if (!empty($which)) { + return $which; + } + + $which = trim(shell_exec('which composer.phar')); + + if (!empty($which)) { + return $which; + } + + return null; + } }