Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6a98bfa

Browse files
Revert "feature #24763 [Process] Allow writing portable "prepared" command lines (Simperfit)"
This reverts commit 1364089, reversing changes made to e043478.
1 parent 1f7b9f0 commit 6a98bfa

File tree

2 files changed

+3
-57
lines changed

2 files changed

+3
-57
lines changed

src/Symfony/Component/Process/Process.php

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -258,21 +258,18 @@ public function start(callable $callback = null, array $env = array())
258258
$this->hasCallback = null !== $callback;
259259
$descriptors = $this->getDescriptors();
260260

261-
if ($this->env) {
262-
$env += $this->env;
263-
}
264-
265261
if (is_array($commandline = $this->commandline)) {
266262
$commandline = implode(' ', array_map(array($this, 'escapeArgument'), $commandline));
267263

268264
if ('\\' !== DIRECTORY_SEPARATOR) {
269265
// exec is mandatory to deal with sending a signal to the process
270266
$commandline = 'exec '.$commandline;
271267
}
272-
} else {
273-
$commandline = $this->replacePlaceholders($commandline, $env);
274268
}
275269

270+
if ($this->env) {
271+
$env += $this->env;
272+
}
276273
$env += $this->getDefaultEnv();
277274

278275
$options = array('suppress_errors' => true);
@@ -1552,29 +1549,6 @@ private function escapeArgument(string $argument): string
15521549
return '"'.str_replace(array('"', '^', '%', '!', "\n"), array('""', '"^^"', '"^%"', '"^!"', '!LF!'), $argument).'"';
15531550
}
15541551

1555-
private function replacePlaceholders(string $commandline, array $env)
1556-
{
1557-
$pattern = '\\' === DIRECTORY_SEPARATOR ? '!%s!' : '"$%s"';
1558-
1559-
return preg_replace_callback('/\{\{ ?([_a-zA-Z0-9]++) ?\}\}/', function ($m) use ($pattern, $commandline, $env) {
1560-
if (!isset($env[$m[1]]) || false === $env[$m[1]]) {
1561-
foreach ($env as $k => $v) {
1562-
if (false === $v) {
1563-
unset($env[$k]);
1564-
}
1565-
}
1566-
if (!$env) {
1567-
throw new InvalidArgumentException(sprintf('Invalid command line "%s": no values provided for any placeholders.', $commandline));
1568-
}
1569-
$env = implode('", "', array_keys($env));
1570-
1571-
throw new InvalidArgumentException(sprintf('Invalid command line "%s": no value provided for placeholder "%s", did you mean "%s"?', $commandline, $m[1], $env));
1572-
}
1573-
1574-
return sprintf($pattern, $m[1]);
1575-
}, $commandline);
1576-
}
1577-
15781552
private function getDefaultEnv()
15791553
{
15801554
$env = array();

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

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,34 +1474,6 @@ public function provideEscapeArgument()
14741474
yield array('éÉèÈàÀöä');
14751475
}
14761476

1477-
public function testPreparedCommand()
1478-
{
1479-
$p = new Process(self::$phpBin.' -r \'print_r($argv);\' {{ abc }}DEF');
1480-
$p->run(null, array('abc' => 'A" B "C'));
1481-
1482-
$this->assertContains('A" B "CDEF', $p->getOutput());
1483-
}
1484-
1485-
/**
1486-
* @expectedException \Symfony\Component\Process\Exception\InvalidArgumentException
1487-
* @expectedExceptionMessage Invalid command line "echo {{ abc }}": no value provided for placeholder "abc", did you mean "bcd"?
1488-
*/
1489-
public function testPreparedCommandWithMissingValue()
1490-
{
1491-
$p = new Process('echo {{ abc }}');
1492-
$p->run(null, array('bcd' => 'BCD'));
1493-
}
1494-
1495-
/**
1496-
* @expectedException \Symfony\Component\Process\Exception\InvalidArgumentException
1497-
* @expectedExceptionMessage Invalid command line "echo {{ abc }}": no values provided for any placeholders.
1498-
*/
1499-
public function testPreparedCommandWithNoValues()
1500-
{
1501-
$p = new Process('echo {{ abc }}');
1502-
$p->run();
1503-
}
1504-
15051477
public function testEnvArgument()
15061478
{
15071479
$env = array('FOO' => 'Foo', 'BAR' => 'Bar');

0 commit comments

Comments
 (0)