Please sign in to comment.
feature #21474 [Process] Accept command line arrays and per-run env v…
…ars, fixing signaling and escaping (nicolas-grekas) This PR was merged into the 3.3-dev branch. Discussion ---------- [Process] Accept command line arrays and per-run env vars, fixing signaling and escaping | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #12488, #11972, #10025, #11335, #5759, #5030, #19993, #10486 | License | MIT | Doc PR | - I think I found a way to fix this network of issues once for all. Of all the linked ones, only the last two are still open: the remaining were closed in dead ends. Instead of trying to make `ProcessUtil::escapeArgument` work correctly on Windows - which is impossible as discussed in #21347 - this PR deprecates it in favor of a more powerful approach. Depending on the use case: - when a simple command should be run, `Process` now accepts an array of arguments (the "binary" being the first arg). Making this the responsibility of `Process` (instead of `ProcessBuilder`) gives two benefits: - escape becomes an internal detail that doesn't leak - thus can't be misused ([see here](#21347 (comment))) - since we know we're running a single command, we can prefix it automatically by "exec" - thus fixing a long standing issue with signaling ```php $p = new Process(array('php', '-r', 'echo 123;')); echo $p->getCommandLine(); // displays on Linux: // exec 'php' '-r' 'echo 123;' ``` - when a shell expression is required, passing a string is still allowed. To make it easy and look-like sql prepared statements, env vars can be used when running the command. Since the shell is OS-specific (think Windows vs Linux) - this PR assumes no portability, so one should just use each shell's specific syntax. From the fixtures: ```php $env = array('FOO' => 'Foo', 'BAR' => 'Bar'); $cmd = '\\' === DIRECTORY_SEPARATOR ? 'echo !FOO! !BAR! !BAZ!' : 'echo $FOO $BAR $BAZ'; $p = new Process($cmd, null, $env); $p->run(null, array('BAR' => 'baR', 'BAZ' => 'baZ')); $this->assertSame('Foo baR baZ', rtrim($p->getOutput())); $this->assertSame($env, $p->getEnv()); ``` Commits ------- 330b61f [Process] Accept command line arrays and per-run env vars, fixing signaling and escaping
- Loading branch information...
Showing with 260 additions and 114 deletions.
- +2 −0 UPGRADE-3.3.md
- +2 −0 UPGRADE-4.0.md
- +3 −0 src/Symfony/Component/Process/CHANGELOG.md
- +6 −9 src/Symfony/Component/Process/PhpProcess.php
- +125 −21 src/Symfony/Component/Process/Process.php
- +1 −3 src/Symfony/Component/Process/ProcessBuilder.php
- +4 −0 src/Symfony/Component/Process/ProcessUtils.php
- +3 −5 src/Symfony/Component/Process/Tests/PhpProcessTest.php
- +16 −16 src/Symfony/Component/Process/Tests/ProcessBuilderTest.php
- +95 −60 src/Symfony/Component/Process/Tests/ProcessTest.php
- +3 −0 src/Symfony/Component/Process/Tests/ProcessUtilsTest.php
Oops, something went wrong.