Make finding composer cross-platform

master
Jordi Boggiano 9 years ago
parent a5c4cf878c
commit 4afdc4629a
  1. 14
      lib/MelodyPlugin.php

@ -4,6 +4,7 @@ use SensioLabs\Melody\Melody;
use SensioLabs\Melody\Configuration\RunConfiguration; use SensioLabs\Melody\Configuration\RunConfiguration;
use Symfony\Component\Process\Process; use Symfony\Component\Process\Process;
use SensioLabs\Melody\Resource\ResourceParser; use SensioLabs\Melody\Resource\ResourceParser;
use Symfony\Component\Process\ExecutableFinder;
/** /**
* Class which integrates melody scripts into the php-console. * Class which integrates melody scripts into the php-console.
@ -17,9 +18,14 @@ class MelodyPlugin {
} }
public function isScriptingSupported() { public function isScriptingSupported() {
// the melody lib is bundled with the console, so the only additional requirement is a composer CLI $executableFinder = new ExecutableFinder();
exec('which composer', $out, $ret); foreach (['composer', 'composer.phar'] as $candidateName) {
return $ret === 0; if ($composerPath = $executableFinder->find($candidateName, null, array(getcwd()))) {
return true;
}
}
return false;
} }
public function runScript($__source_code, $__bootstrap_file) public function runScript($__source_code, $__bootstrap_file)
@ -56,4 +62,4 @@ class MelodyPlugin {
file_put_contents($tmpFile, $__source_code); file_put_contents($tmpFile, $__source_code);
$melody->run($tmpFile, array(), $configuration, $executor); $melody->run($tmpFile, array(), $configuration, $executor);
} }
} }

Loading…
Cancel
Save