Skip to content

[Process] Deprecate ProcessBuilder #23111

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
Jun 9, 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
6 changes: 6 additions & 0 deletions UPGRADE-3.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ FrameworkBundle
* The `KernelTestCase::getPhpUnitXmlDir()` and `KernelTestCase::getPhpUnitCliConfigArgument()`
methods are deprecated since 3.4 and will be removed in 4.0.

Process
-------

* The `Symfony\Component\Process\ProcessBuilder` class has been deprecated,
use the `Symfony\Component\Process\Process` class directly instead.

Validator
---------

Expand Down
3 changes: 3 additions & 0 deletions UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,9 @@ Ldap
Process
-------

* The `Symfony\Component\Process\ProcessBuilder` class has been removed,
use the `Symfony\Component\Process\Process` class directly instead.

* The `ProcessUtils::escapeArgument()` method has been removed, use a command line array or give env vars to the `Process::start/run()` method instead.

* Environment variables are always inherited in sub-processes.
Expand Down
9 changes: 4 additions & 5 deletions src/Symfony/Bundle/WebServerBundle/WebServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\ProcessBuilder;
use Symfony\Component\Process\Exception\RuntimeException;

/**
Expand Down Expand Up @@ -151,11 +150,11 @@ private function createServerProcess(WebServerConfig $config)
throw new \RuntimeException('Unable to find the PHP binary.');
}

$builder = new ProcessBuilder(array($binary, '-S', $config->getAddress(), $config->getRouter()));
$builder->setWorkingDirectory($config->getDocumentRoot());
$builder->setTimeout(null);
$process = new Process(array($binary, '-S', $config->getAddress(), $config->getRouter()));
$process->setWorkingDirectory($config->getDocumentRoot());
$process->setTimeout(null);

return $builder->getProcess();
return $process;
}

private function getDefaultPidFile()
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/WebServerBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"php": ">=5.5.9",
"symfony/console": "~2.8.8|~3.0.8|~3.1.2|~3.2|~4.0",
"symfony/http-kernel": "~3.3|~4.0",
"symfony/process": "~2.8|~3.0|~4.0"
"symfony/process": "~3.3|~4.0"
},
"autoload": {
"psr-4": { "Symfony\\Bundle\\WebServerBundle\\": "" },
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/Console/Helper/ProcessHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\ProcessBuilder;

/**
* The ProcessHelper class provides helpers to run external processes.
Expand Down Expand Up @@ -45,7 +44,7 @@ public function run(OutputInterface $output, $cmd, $error = null, callable $call
$formatter = $this->getHelperSet()->get('debug_formatter');

if (is_array($cmd)) {
$process = ProcessBuilder::create($cmd)->getProcess();
$process = new Process($cmd);
} elseif ($cmd instanceof Process) {
$process = $cmd;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Symfony\Component\Console\Output\StreamOutput;
use Symfony\Component\Console\Helper\ProcessHelper;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\ProcessBuilder;

class ProcessHelperTest extends TestCase
{
Expand Down Expand Up @@ -85,8 +84,8 @@ public function provideCommandsAndOutput()
EOT;

$errorMessage = 'An error occurred';
$args = new ProcessBuilder(array('php', '-r', 'echo 42;'));
$args = $args->getProcess()->getCommandLine();
$args = new Process(array('php', '-r', 'echo 42;'));
$args = $args->getCommandLine();
$successOutputProcessDebug = str_replace("'php' '-r' 'echo 42;'", $args, $successOutputProcessDebug);

return array(
Expand Down
5 changes: 3 additions & 2 deletions src/Symfony/Component/Console/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"symfony/event-dispatcher": "~2.8|~3.0|~4.0",
"symfony/dependency-injection": "~3.3|~4.0",
"symfony/filesystem": "~2.8|~3.0|~4.0",
"symfony/process": "~2.8|~3.0|~4.0",
"symfony/process": "~3.3|~4.0",
"psr/log": "~1.0"
},
"suggest": {
Expand All @@ -36,7 +36,8 @@
"psr/log": "For using the console logger"
},
"conflict": {
"symfony/dependency-injection": "<3.3"
"symfony/dependency-injection": "<3.3",
"symfony/process": "<3.3"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Console\\": "" },
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Process/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

3.4.0
-----

* deprecated the ProcessBuilder class

3.3.0
-----

Expand Down
12 changes: 4 additions & 8 deletions src/Symfony/Component/Process/ProcessBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@

namespace Symfony\Component\Process;

@trigger_error(sprintf('The %s class is deprecated since version 3.4 and will be removed in 4.0. Use the Process class instead.', ProcessBuilder::class), E_USER_DEPRECATED);

use Symfony\Component\Process\Exception\InvalidArgumentException;
use Symfony\Component\Process\Exception\LogicException;

/**
* Process builder.
*
* @author Kris Wallsmith <kris@symfony.com>
*
* @deprecated since version 3.4, to be removed in 4.0. Use the Process class instead.
*/
class ProcessBuilder
{
Expand Down Expand Up @@ -120,13 +124,9 @@ public function setWorkingDirectory($cwd)
* @param bool $inheritEnv
*
* @return $this
*
* @deprecated since version 3.3, to be removed in 4.0.
*/
public function inheritEnvironmentVariables($inheritEnv = true)
{
@trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);

$this->inheritEnv = $inheritEnv;

return $this;
Expand Down Expand Up @@ -221,13 +221,9 @@ public function setTimeout($timeout)
* @param string $value The option value
*
* @return $this
*
* @deprecated since version 3.3, to be removed in 4.0.
*/
public function setOption($name, $value)
{
@trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);

$this->options[$name] = $value;

return $this;
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Process/Tests/ProcessBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\ProcessBuilder;

/**
* @group legacy
*/
class ProcessBuilderTest extends TestCase
{
/**
* @group legacy
*/
public function testInheritEnvironmentVars()
{
$proc = ProcessBuilder::create()
Expand Down