10000 [Process] Fix BC break: "exec" should remain an internal "detail" by nicolas-grekas · Pull Request #22487 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Process] Fix BC break: "exec" should remain an internal "detail" #22487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Process] Fix BC break: "exec" should remain an internal "detail"
  • Loading branch information
nicolas-grekas committed Apr 20, 2017
commit eedcece20b752d8a2d807c8bc9b8e6f67af2d594
24 changes: 12 additions & 12 deletions src/Symfony/Component/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function __construct($commandline, $cwd = null, array $env = null, $input
throw new RuntimeException('The Process class relies on proc_open, which is not available on your PHP installation.');
}

$this->setCommandLine($commandline);
$this->commandline = $commandline;
$this->cwd = $cwd;

// on Windows, if the cwd changed via chdir(), proc_open defaults to the dir where PHP was started
Expand Down Expand Up @@ -289,7 +289,15 @@ public function start(callable $callback = null/*, array $env = array()*/)
$this->hasCallback = null !== $callback;
$descriptors = $this->getDescriptors();
$inheritEnv = $this->inheritEnv;
$commandline = $this->commandline;

if (is_array($commandline = $this->commandline)) {
$commandline = implode(' ', array_map(array($this, 'escapeArgument'), $commandline));

if ('\\' !== DIRECTORY_SEPARATOR) {
// exec is mandatory to deal with sending a signal to the process
$commandline = 'exec '.$commandline;
}
}

if (null === $env) {
$env = $this->env;
Expand Down Expand Up @@ -318,7 +326,7 @@ public function start(callable $callback = null/*, array $env = array()*/)
$descriptors[3] = array('pipe', 'w');

// See https://unix.stackexchange.com/questions/71205/background-process-pipe-input
$commandline = '{ ('.$this->commandline.') <&3 3<&- 3>/dev/null & } 3<&0;';
$commandline = '{ ('.$commandline.') <&3 3<&- 3>/dev/null & } 3<&0;';
$commandline .= 'pid=$!; echo $pid >&3; wait $pid; code=$?; echo $code >&3; exit $code';

// Workaround for the bug, when PTS functionality is enabled.
Expand Down Expand Up @@ -928,7 +936,7 @@ public function addErrorOutput($line)
*/
public function getCommandLine()
{
return $this->commandline;
return is_array($this->commandline) ? implode(' ', array_map(array($this, 'escapeArgument'), $this->commandline)) : $this->commandline;
}

/**
Expand All @@ -940,14 +948,6 @@ public function getCommandLine()
*/
public function setCommandLine($commandline)
{
if (is_array($commandline)) {
$commandline = implode(' ', array_map(array($this, 'escapeArgument'), $commandline));

if ('\\' !== DIRECTORY_SEPARATOR) {
// exec is mandatory to deal with sending a signal to the process
$commandline = 'exec '.$commandline;
}
}
$this->commandline = $commandline;

return $this;
Expand Down
16 changes: 8 additions & 8 deletions src/Symfony/Component/Process/Tests/ProcessBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ public function testPrefixIsPrependedToAllGeneratedProcess()
if ('\\' === DIRECTORY_SEPARATOR) {
$this->assertEquals('/usr/bin/php -v', $proc->getCommandLine());
} else {
$this->assertEquals("exec '/usr/bin/php' '-v'", $proc->getCommandLine());
$this->assertEquals("'/usr/bin/php' '-v'", $proc->getCommandLine());
}

$proc = $pb->setArguments(array('-i'))->getProcess();
if ('\\' === DIRECTORY_SEPARATOR) {
$this->assertEquals('/usr/bin/php -i', $proc->getCommandLine());
} else {
$this->assertEquals("exec '/usr/bin/php' '-i'", $proc->getCommandLine());
$this->assertEquals("'/usr/bin/php' '-i'", $proc->getCommandLine());
}
}

Expand All @@ -113,14 +113,14 @@ public function testArrayPrefixesArePrependedToAllGeneratedProcess()
if ('\\' === DIRECTORY_SEPARATOR) {
$this->assertEquals('/usr/bin/php composer.phar -v', $proc->getCommandLine());
} else {
$this->assertEquals("exec '/usr/bin/php' 'composer.phar' '-v'", $proc->getCommandLine());
$this->assertEquals("'/usr/bin/php' 'composer.phar' '-v'", $proc->getCommandLine());
}

$proc = $pb->setArguments(array('-i'))->getProcess();
if ('\\' === DIRECTORY_SEPARATOR) {
$this->assertEquals('/usr/bin/php composer.phar -i', $proc->getCommandLine());
} else {
$this->assertEquals("exec '/usr/bin/php' 'composer.phar' '-i'", $proc->getCommandLine());
$this->assertEquals("'/usr/bin/php' 'composer.phar' '-i'", $proc->getCommandLine());
}
}

Expand All @@ -132,7 +132,7 @@ public function testShouldEscapeArguments()
if ('\\' === DIRECTORY_SEPARATOR) {
$this->assertSame('""^%"path"^%"" "foo "" bar" ""^%"baz"^%"baz"', $proc->getCommandLine());
} else {
$this->assertSame("exec '%path%' 'foo \" bar' '%baz%baz'", $proc->getCommandLine());
$this->assertSame("'%path%' 'foo \" bar' '%baz%baz'", $proc->getCommandLine());
}
}

Expand All @@ -145,7 +145,7 @@ public function testShouldEscapeArgumentsAndPrefix()
if ('\\' === DIRECTORY_SEPARATOR) {
$this->assertSame('""^%"prefix"^%"" arg', $proc->getCommandLine());
} else {
$this->assertSame("exec '%prefix%' 'arg'", $proc->getCommandLine());
$this->assertSame("'%prefix%' 'arg'", $proc->getCommandLine());
}
}

Expand All @@ -166,7 +166,7 @@ public function testShouldNotThrowALogicExceptionIfNoArgument()
if ('\\' === DIRECTORY_SEPARATOR) {
$this->assertEquals('/usr/bin/php', $process->getCommandLine());
} else {
$this->assertEquals("exec '/usr/bin/php'", $process->getCommandLine());
$this->assertEquals("'/usr/bin/php'", $process->getCommandLine());
}
}

Expand All @@ -178,7 +178,7 @@ public function testShouldNotThrowALogicExceptionIfNoPrefix()
if ('\\' === DIRECTORY_SEPARATOR) {
$this->assertEquals('/usr/bin/php', $process->getCommandLine());
} else {
$this->assertEquals("exec '/usr/bin/php'", $process->getCommandLine());
$this->assertEquals("'/usr/bin/php'", $process->getCommandLine());
}
}

Expand Down
0