diff --git a/src/Psy/Command/ComposerCommand.php b/src/Psy/Command/ComposerCommand.php
index 529aef9c2..3deea2909 100644
--- a/src/Psy/Command/ComposerCommand.php
+++ b/src/Psy/Command/ComposerCommand.php
@@ -6,14 +6,22 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Process\Process;
-/**
- * Class ComposerCommand
- * @package Psy\Command
- */
class ComposerCommand extends Command
{
+ const PIPE_WRITE = 0;
+ const PIPE_READ = 1;
+ const PIPE_ERR = 2;
+
+ /**
+ * @var array
+ */
+ protected $specification = array(
+ self::PIPE_WRITE => array("pipe", "r"),
+ self::PIPE_READ => array("pipe", "w"),
+ self::PIPE_ERR => array("pipe", "w"),
+ );
+
/**
* @var string
*/
@@ -71,6 +79,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
return $app->doRun($input, $this->output);
}
+ /**
+ * @param $path
+ */
public function setComposerPath($path)
{
$this->composerPath = $path;
@@ -91,32 +102,65 @@ protected function callComposerBootstrap()
/**
* @param $command
+ *
* @return bool|string
*/
protected function shellCommand($command)
{
- /** PHP 5.4 compatibility, closures have no this scope in 5.4 versions */
- $output = $this->output;
- $process = new Process($command);
- $process->run(function ($type, $buffer) use ($output) {
- if (Process::ERR === $type) {
- $this->output->writeln("$buffer");
+ $process = proc_open($this->getSystemShell(), $this->specification, $pipes);
+ stream_set_blocking($pipes[self::PIPE_ERR], 0);
+
+ if (is_resource($process)) {
+ fwrite($pipes[self::PIPE_WRITE], $command);
+ fclose($pipes[self::PIPE_WRITE]);
+
+ if ($err = stream_get_contents($pipes[self::PIPE_ERR])) {
+ $err = trim($err);
+ $this->output->writeln("$err");
+
+ return false;
}
- });
- return $process->getOutput();
+ $return = stream_get_contents($pipes[self::PIPE_READ]);
+ fclose($pipes[self::PIPE_READ]);
+
+ if (proc_close($process) === 0) {
+ return trim($return);
+ }
+ }
}
+ /**
+ * @return string
+ */
+ protected function getSystemShell()
+ {
+ if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
+ return 'cmd.exe';
+ }
+
+ return 'bash';
+ }
+
+ /**
+ * @return string
+ */
protected function getLocalComposerFile()
{
return getcwd() . DIRECTORY_SEPARATOR . 'composer.phar';
}
+ /**
+ * @return bool
+ */
protected function checkComposerInstallation()
{
return @file_exists($this->getLocalComposerFile()) or !is_null($this->composerPath);
}
+ /**
+ *
+ */
protected function installComposer()
{
$this->output->writeln("Composer not found, downloading.");
diff --git a/src/Psy/Command/SandboxCommand.php b/src/Psy/Command/SandboxCommand.php
index 8d9ff0890..533d644b2 100644
--- a/src/Psy/Command/SandboxCommand.php
+++ b/src/Psy/Command/SandboxCommand.php
@@ -7,10 +7,6 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-/**
- * Class SandboxCommand
- * @package Psy\Command
- */
class SandboxCommand extends Command
{
const SANDBOX_FOLDER = 'psysh_sandbox';
@@ -160,6 +156,7 @@ protected function showUsage()
/**
* @param $name
+ *
* @return string
*/
protected function getSandboxPath($name)
@@ -168,7 +165,8 @@ protected function getSandboxPath($name)
}
/**
- * @param null $name
+ * @param null $name
+ *
* @return null|string
*/
protected function createSandbox($name = null)