8000 [Process] Accept command line arrays and per-run env vars, fixing sig… · symfony/symfony@dceca99 · GitHub
[go: up one dir, main page]

Skip to content

Commit dceca99

Browse files
[Process] Accept command line arrays and per-run env vars, fixing signaling and escaping
1 parent 00ab4b3 commit dceca99

13 files changed

+285
-136
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ script:
9696
- if [[ ! $deps && ! $PHP = hhvm* ]]; then echo "$COMPONENTS" | parallel --gnu '$PHPUNIT --exclude-group tty,benchmark,intl-data {}'"$REPORT"; fi
9797
- if [[ ! $deps && ! $PHP = hhvm* ]]; then echo -e "\\nRunning tests requiring tty"; $PHPUNIT --group tty; fi
9898
- if [[ ! $deps && $PHP = hhvm* ]]; then $PHPUNIT --exclude-group benchmark,intl-data; fi
99-
- if [[ ! $deps && $PHP = ${MIN_PHP%.*} ]]; then echo -e "1\\n0" | xargs -I{} sh -c 'echo "\\nPHP --enable-sigchild enhanced={}" && ENHANCE_SIGCHLD={} php-$MIN_PHP/sapi/cli/php .phpunit/phpunit-4.8/phpunit --colors=always src/Symfony/Component/Process/'; fi
99+
- if [[ ! $deps && $PHP = ${MIN_PHP%.*} ]]; then echo -e "1\\n0" | xargs -I{} sh -c 'echo "\\nPHP --enable-sigchild enhanced={}" && SYMFONY_DEPRECATIONS_HELPER=weak ENHANCE_SIGCHLD={} php-$MIN_PHP/sapi/cli/php .phpunit/phpunit-4.8/phpunit --colors=always src/Symfony/Component/Process/'; fi
100100
- if [[ $deps = high ]]; then echo "$COMPONENTS" | parallel --gnu -j10% 'cd {}; composer update --no-progress --ansi; $PHPUNIT --exclude-group tty,benchmark,intl-data'$LEGACY"$REPORT"; fi
101101
- if [[ $deps = low ]]; then echo "$COMPONENTS" | parallel --gnu -j10% 'cd {}; composer update --no-progress --ansi --prefer-lowest --prefer-stable; $PHPUNIT --exclude-group tty,benchmark,intl-data'"$REPORT"; fi
102102
# Test the PhpUnit bridge using the original phpunit script

UPGRADE-3.3.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ HttpKernel
4646
* The `Psr6CacheClearer::addPool()` method has been deprecated. Pass an array of pools indexed
4747
by name to the constructor instead.
4848

49+
Process
50+
-------
51+
52+
* The `ProcessUtils::escapeArgument()` method has been deprecated, use a command line array or give env vars to the `Process::start/run()` method instead.
53+
4954
Security
5055
--------
5156

UPGRADE-4.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ HttpKernel
206206
* The `Psr6CacheClearer::addPool()` method has been removed. Pass an array of pools indexed
207207
by name to the constructor instead.
208208

209+
Process
210+
-------
211+
212+
* The `ProcessUtils::escapeArgument()` method has been removed, use a command line array or give env vars to the `Process::start/run()` method instead.
213+
209214
Security
210215
--------
211216

src/Symfony/Component/Console/Tests/Helper/ProcessHelperTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Console\Output\StreamOutput;
1717
use Symfony\Component\Console\Helper\ProcessHelper;
1818
use Symfony\Component\Process\Process;
19+
use Symfony\Component\Process\ProcessBuilder;
1920

2021
class ProcessHelperTest extends \PHPUnit_Framework_TestCase
2122
{
@@ -83,9 +84,9 @@ public function provideCommandsAndOutput()
8384
EOT;
8485

8586
$errorMessage = 'An error occurred';
86-
if ('\\' === DIRECTORY_SEPARATOR) {
87-
$successOutputProcessDebug = str_replace("'", '"', $successOutputProcessDebug);
88-
}
87+
$args = new ProcessBuilder(array('php', '-r', 'echo 42;'));
88+
$args = $args->getProcess()->getCommandLine();
89+
$successOutputProcessDebug = str_replace("'php' '-r' 'echo 42;'", $args, $successOutputProcessDebug);
8990

9091
return array(
9192
array('', 'php -r "echo 42;"', StreamOutput::VERBOSITY_VERBOSE, null),

src/Symfony/Component/Process/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
CHANGELOG
22
=========
33

4+
3.3.0
5+
-----
6+
7+
* added command line arrays in the `Process` class
8+
* added `$env` argument to `Process::start()`, `run()`, `mustRun()` and `restart()` methods
9+
* deprecated the `ProcessUtils::escapeArgument()` method
10+
411
2.5.0
512
-----
613

src/Symfony/Component/Process/PhpProcess.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,16 @@ public function __construct($script, $cwd = null, array $env = null, $timeout =
3838
$executableFinder = new PhpExecutableFinder();
3939
if (false === $php = $executableFinder->find()) {
4040
$php = null;
41+
} else {
42+
$php = explode(' ', $php);
4143
}
4244
if ('phpdbg' === PHP_SAPI) {
4345
$file = tempnam(sys_get_temp_dir(), 'dbg');
4446
file_put_contents($file, $script);
4547
register_shutdown_function('unlink', $file);
46-
$php .= ' '.ProcessUtils::escapeArgument($file);
48+
$php[] = $file;
4749
$script = null;
4850
}
49-
if ('\\' !== DIRECTORY_SEPARATOR && null !== $php) {
50-
// exec is mandatory to deal with sending a signal to the process
51-
// see https://github.com/symfony/symfony/issues/5030 about prepending
52-
// command with exec
53-
$php = 'exec '.$php;
54-
}
5551

5652
parent::__construct($php, $cwd, $env, $script, $timeout, $options);
5753
}
@@ -67,12 +63,13 @@ public function setPhpBinary($php)
6763
/**
6864
* {@inheritdoc}
6965
*/
70-
public function start(callable $callback = null)
66+
public function start(callable $callback = null/*, array $env = array()*/)
7167
{
7268
if (null === $this->getCommandLine()) {
7369
throw new RuntimeException('Unable to find the PHP executable.');
7470
}
71+
$env = 1 < func_num_args() ? func_get_arg(1) : null;
7572

76-
parent::start($callback);
73+
parent::start($callback, $env);
7774
}
7875
}

0 commit comments

Comments
 (0)
0