8000 bug #22487 [Process] Fix BC break: "exec" should remain an internal "… · symfony/symfony@63dca04 · GitHub
[go: up one dir, main page]

Skip to content

Commit 63dca04

Browse files
committed
bug #22487 [Process] Fix BC break: "exec" should remain an internal "detail" (nicolas-grekas)
This PR was merged into the 3.3-dev branch. Discussion ---------- [Process] Fix BC break: "exec" should remain an internal "detail" | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #22476 | License | MIT | Doc PR | - Commits ------- eedcece [Process] Fix BC break: "exec" should remain an internal "detail"
2 parents 60c51d9 + eedcece commit 63dca04

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

src/Symfony/Component/Process/Process.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function __construct($commandline, $cwd = null, array $env = null, $input
151151
throw new RuntimeException('The Process class relies on proc_open, which is not available on your PHP installation.');
152152
}
153153

154-
$this->setCommandLine($commandline);
154+
$this->commandline = $commandline;
155155
$this->cwd = $cwd;
156156

157157
// on Windows, if the cwd changed via chdir(), proc_open defaults to the dir where PHP was started
@@ -289,7 +289,15 @@ public function start(callable $callback = null/*, array $env = array()*/)
289289
$this->hasCallback = null !== $callback;
290290
$descriptors = $this->getDescriptors();
291291
$inheritEnv = $this->inheritEnv;
292-
$commandline = $this->commandline;
292+
293+
if (is_array($commandline = $this->commandline)) {
294+
$commandline = implode(' ', array_map(array($this, 'escapeArgument'), $commandline));
295+
296+
if ('\\' !== DIRECTORY_SEPARATOR) {
297+
// exec is mandatory to deal with sending a signal to the process
298+
$commandline = 'exec '.$commandline;
299+
}
300+
}
293301

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

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

324332
// Workaround for the bug, when PTS functionality is enabled.
@@ -928,7 +936,7 @@ public function addErrorOutput($line)
928936
*/
929937
public function getCommandLine()
930938
{
931-
return $this->commandline;
939+
return is_array($this->commandline) ? implode(' ', array_map(array($this, 'escapeArgument'), $this->commandline)) : $this->commandline;
932940
}
933941

934942
/**
@@ -940,14 +948,6 @@ public function getCommandLine()
940948
*/
941949
public function setCommandLine($commandline)
942950
{
943-
if (is_array($commandline)) {
944-
$commandline = implode(' ', array_map(array($this, 'escapeArgument'), $commandline));
945-
946-
if ('\\' !== DIRECTORY_SEPARATOR) {
947-
// exec is mandatory to deal with sending a signal to the process
948-
$commandline = 'exec '.$commandline;
949-
}
950-
}
951951
$this->commandline = $commandline;
952952

953953
return $this;

src/Symfony/Component/Process/Tests/ProcessBuilderTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ public function testPrefixIsPrependedToAllGeneratedProcess()
9393
if ('\\' === DIRECTORY_SEPARATOR) {
9494
$this->assertEquals('/usr/bin/php -v', $proc->getCommandLine());
9595
} else {
96-
$this->assertEquals("exec '/usr/bin/php' '-v'", $proc->getCommandLine());
96+
$this->assertEquals("'/usr/bin/php' '-v'", $proc->getCommandLine());
9797
}
9898

9999
$proc = $pb->setArguments(array('-i'))->getProcess();
100100
if ('\\' === DIRECTORY_SEPARATOR) {
101101
$this->assertEquals('/usr/bin/php -i', $proc->getCommandLine());
102102
} else {
103-
$this->assertEquals("exec '/usr/bin/php' '-i'", $proc->getCommandLine());
103+
$this->assertEquals("'/usr/bin/php' '-i'", $proc->getCommandLine());
104104
}
105105
}
106106

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

119119
$proc = $pb->setArguments(array('-i'))->getProcess();
120120
if ('\\' === DIRECTORY_SEPARATOR) {
121121
$this->assertEquals('/usr/bin/php composer.phar -i', $proc->getCommandLine());
122122
} else {
123-
$this->assertEquals("exec '/usr/bin/php' 'composer.phar' '-i'", $proc->getCommandLine());
123+
$this->assertEquals("'/usr/bin/php' 'composer.phar' '-i'", $proc->getCommandLine());
124124
}
125125
}
126126

@@ -132,7 +132,7 @@ public function testShouldEscapeArguments()
132132
if ('\\' === DIRECTORY_SEPARATOR) {
133133
$this->assertSame('""^%"path"^%"" "foo "" bar" ""^%"baz"^%"baz"', $proc->getCommandLine());
134134
} else {
135-
$this->assertSame("exec '%path%' 'foo \" bar' '%baz%baz'", $proc->getCommandLine());
135+
$this->assertSame("'%path%' 'foo \" bar' '%baz%baz'", $proc->getCommandLine());
136136
}
137137
}
138138

@@ -145,7 +145,7 @@ public function testShouldEscapeArgumentsAndPrefix()
145145
if ('\\' === DIRECTORY_SEPARATOR) {
146146
$this->assertSame('""^%"prefix"^%"" arg', $proc->getCommandLine());
147147
} else {
148-
$this->assertSame("exec '%prefix%' 'arg'", $proc->getCommandLine());
148+
$this->assertSame("'%prefix%' 'arg'", $proc->getCommandLine());
149149
}
150150
}
151151

@@ -166,7 +166,7 @@ public function testShouldNotThrowALogicExceptionIfNoArgument()
166166
if ('\\' === DIRECTORY_SEPARATOR) {
167167
$this->assertEquals('/usr/bin/php', $process->getCommandLine());
168168
} else {
169-
$this->assertEquals("exec '/usr/bin/php'", $process->getCommandLine());
169+
$this->assertEquals("'/usr/bin/php'", $process->getCommandLine());
170170
}
171171
}
172172

@@ -178,7 +178,7 @@ public function testShouldNotThrowALogicExceptionIfNoPrefix()
178178
if ('\\' === DIRECTORY_SEPARATOR) {
179179
$this->assertEquals('/usr/bin/php', $process->getCommandLine());
180180
} else {
181-
$this->assertEquals("exec '/usr/bin/php'", $process->getCommandLine());
181+
$this->assertEquals("'/usr/bin/php'", $process->getCommandLine());
182182
}
183183
}
184184

0 commit comments

Comments
 (0)
0