From 4afdc4629a242e9d9b82791a1141d9add2a13e28 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 28 Apr 2015 15:45:07 +0100 Subject: [PATCH] Make finding composer cross-platform --- lib/MelodyPlugin.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/MelodyPlugin.php b/lib/MelodyPlugin.php index f66fca4..93fbf1f 100644 --- a/lib/MelodyPlugin.php +++ b/lib/MelodyPlugin.php @@ -4,6 +4,7 @@ use SensioLabs\Melody\Melody; use SensioLabs\Melody\Configuration\RunConfiguration; use Symfony\Component\Process\Process; use SensioLabs\Melody\Resource\ResourceParser; +use Symfony\Component\Process\ExecutableFinder; /** * Class which integrates melody scripts into the php-console. @@ -17,9 +18,14 @@ class MelodyPlugin { } public function isScriptingSupported() { - // the melody lib is bundled with the console, so the only additional requirement is a composer CLI - exec('which composer', $out, $ret); - return $ret === 0; + $executableFinder = new ExecutableFinder(); + foreach (['composer', 'composer.phar'] as $candidateName) { + if ($composerPath = $executableFinder->find($candidateName, null, array(getcwd()))) { + return true; + } + } + + return false; } public function runScript($__source_code, $__bootstrap_file) @@ -56,4 +62,4 @@ class MelodyPlugin { file_put_contents($tmpFile, $__source_code); $melody->run($tmpFile, array(), $configuration, $executor); } -} \ No newline at end of file +}