8000 [Process] remove deprecated features · simshaun/symfony@e4ec8e9 · GitHub
[go: up one dir, main page]

Skip to content

Commit e4ec8e9

Browse files
committed
[Process] remove deprecated features
1 parent 587b2f7 commit e4ec8e9

File tree

8 files changed

+31
-729
lines changed

8 files changed

+31
-729
lines changed

src/Symfony/Component/Process/CHANGELOG.md

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

4+
4.0.0
5+
-----
6+
7+
* environment variables will always be inherited
8+
* added a second `array $env = array()` argument to the `start()`, `run()`,
9+
`mustRun()`, and `restart()` methods of the `Process` class
10+
* added a second `array $env = array()` argument to the `start()` method of the
11+
`PhpProcess` class
12+
* the `ProcessUtils::escapeArgument()` method has been removed
13+
* the `areEnvironmentVariablesInherited()`, `getOptions()`, and `setOptions()`
14+
methods of the `Process` class have been removed
15+
* support for passing `proc_open()` options has been removed
16+
* removed the `ProcessBuilder` class, use the `Process` class instead
17+
418
3.4.0
519
-----
620

src/Symfony/Component/Process/PhpProcess.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ class PhpProcess extends Process
3131
* @param string|null $cwd The working directory or null to use the working dir of the current PHP process
3232
* @param array|null $env The environment variables or null to use the same environment as the current PHP process
3333
* @param int $timeout The timeout in seconds
34-
* @param array $options An array of options for proc_open
3534
*/
36-
public function __construct($script, $cwd = null, array $env = null, $timeout = 60, array $options = null)
35+
public function __construct($script, $cwd = null, array $env = null, $timeout = 60)
3736
{
3837
$executableFinder = new PhpExecutableFinder();
3938
if (false === $php = $executableFinder->find(false)) {
@@ -48,11 +47,8 @@ public function __construct($script, $cwd = null, array $env = null, $timeout =
4847
$php[] = $file;
4948
$script = null;
5049
}
51-
if (null !== $options) {
52-
@trigger_error(sprintf('The $options parameter of the %s constructor is deprecated since version 3.3 and will be removed in 4.0.', __CLASS__), E_USER_DEPRECATED);
53-
}
5450

55-
parent::__construct($php, $cwd, $env, $script, $timeout, $options);
51+
parent::__construct($php, $cwd, $env, $script, $timeout);
5652
}
5753

5854
/**
@@ -66,12 +62,11 @@ public function setPhpBinary($php)
6662
/**
6763
* {@inheritdoc}
6864
*/
69-
public function start(callable $callback = null/*, array $env = array()*/)
65+
public function start(callable $callback = null, array $env = array())
7066
{
7167
if (null === $this->getCommandLine()) {
7268
throw new RuntimeException('Unable to find the PHP executable.');
7369
}
74-
$env = 1 < func_num_args() ? func_get_arg(1) : null;
7570

7671
parent::start($callback, $env);
7772
}

src/Symfony/Component/Process/Process.php

Lines changed: 14 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ class Process implements \IteratorAggregate
5858
private $lastOutputTime;
5959
private $timeout;
6060
private $idleTimeout;
61-
private $options = array('suppress_errors' => true);
6261
private $exitcode;
6362
private $fallbackStatus = array();
6463
private $processInformation;
@@ -73,7 +72,6 @@ class Process implements \IteratorAggregate
7372
private $incrementalErrorOutputOffset = 0;
7473
private $tty;
7574
private $pty;
76-
private $inheritEnv = false;
7775

7876
private $useFileHandles = false;
7977
/** @var PipesInterface */
@@ -141,11 +139,10 @@ class Process implements \IteratorAggregate
141139
* @param array|null $env The environment variables or null to use the same environment as the current PHP process
142140
* @param mixed|null $input The input as stream resource, scalar or \Traversable, or null for no input
143141
* @param int|float|null $timeout The timeout in seconds or null to disable
144-
* @param array $options An array of options for proc_open
145142
*
146143
* @throws RuntimeException When proc_open is not installed
147144
*/
148-
public function __construct($commandline, $cwd = null, array $env = null, $input = null, $timeout = 60, array $options = null)
145+
public function __construct($commandline, $cwd = null, array $env = null, $input = null, $timeout = 60)
149146
{
150147
if (!function_exists('proc_open')) {
151148
throw new RuntimeException('The Process class relies on proc_open, which is not available on your PHP installation.');
@@ -170,10 +167,6 @@ public function __construct($commandline, $cwd = null, array $env = null, $input
170167
$this->useFileHandles = '\\' === DIRECTORY_SEPARATOR;
171168
$this->pty = false;
172169
$this->enhanceSigchildCompatibility = '\\' !== DIRECTORY_SEPARATOR && $this->isSigchildEnabled();
173-
if (null !== $options) {
174-
@trigger_error(sprintf('The $options parameter of the %s constructor is deprecated since version 3.3 and will be removed in 4.0.', __CLASS__), E_USER_DEPRECATED);
175-
$this->options = array_replace($this->options, $options);
176-
}
177170
}
178171

179172
public function __destruct()
@@ -208,9 +201,8 @@ public function __clone()
208201
*
209202
* @final since version 3.3
210203
*/
211-
public function run($callback = null/*, array $env = array()*/)
204+
public function run($callback = null, array $env = array())
212205
{
213-
$env = 1 < func_num_args() ? func_get_arg(1) : null;
214206
$this->start($callback, $env);
215207

216208
return $this->wait();
@@ -232,12 +224,11 @@ public function run($callback = null/*, array $env = array()*/)
232224
*
233225
* @final since version 3.3
234226
*/
235-
public function mustRun(callable $callback = null/*, array $env = array()*/)
227+
public function mustRun(callable $callback = null, array $env = array())
236228
{
237229
if (!$this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
238230
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.');
239231
}
240-
$env = 1 < func_num_args() ? func_get_arg(1) : null;
241232

242233
if (0 !== $this->run($callback, $env)) {
243234
throw new ProcessFailedException($this);
@@ -266,29 +257,17 @@ public function mustRun(callable $callback = null/*, array $env = array()*/)
266257
* @throws RuntimeException When process is already running
267258
* @throws LogicException In case a callback is provided and output has been disabled
268259
*/
269-
public function start(callable $callback = null/*, array $env = array()*/)
260+
public function start(callable $callback = null, array $env = array())
270261
{
271262
if ($this->isRunning()) {
272263
throw new RuntimeException('Process is already running');
273264
}
274-
if (2 <= func_num_args()) {
275-
$env = func_get_arg(1);
276-
} else {
277-
if (__CLASS__ !== static::class) {
278-
$r = new \ReflectionMethod($this, __FUNCTION__);
279-
if (__CLASS__ !== $r->getDeclaringClass()->getName() && (2 > $r->getNumberOfParameters() || 'env' !== $r->getParameters()[0]->name)) {
280-
@trigger_error(sprintf('The %s::start() method expects a second "$env" argument since version 3.3. It will be made mandatory in 4.0.', static::class), E_USER_DEPRECATED);
281-
}
282-
}
283-
$env = null;
284-
}
285265

286266
$this->resetProcessData();
287267
$this->starttime = $this->lastOutputTime = microtime(true);
288268
$this->callback = $this->buildCallback($callback);
289269
$this->hasCallback = null !== $callback;
290270
$descriptors = $this->getDescriptors();
291-
$inheritEnv = $this->inheritEnv;
292271

293272
if (is_array($commandline = $this->commandline)) {
294273
$commandline = implode(' ', array_map(array($this, 'escapeArgument'), $commandline));
@@ -301,25 +280,23 @@ public function start(callable $callback = null/*, array $env = array()*/)
301280

302281
if (null === $env) {
303282
$env = $this->env;
304-
} else {
305-
if ($this->env) {
306-
$env += $this->env;
307-
}
308-
$inheritEnv = true;
283+
} elseif ($this->env) {
284+
$env += $this->env;
309285
}
310286

311287
$envBackup = array();
312-
if (null !== $env && $inheritEnv) {
288+
if (null !== $env) {
313289
foreach ($env as $k => $v) {
314290
$envBackup[$k] = getenv($k);
315291
putenv(false === $v || null === $v ? $k : "$k=$v");
316292
}
317293
$env = null;
318-
} elseif (null !== $env) {
319-
@trigger_error('Not inheriting environment variables is deprecated since Symfony 3.3 and will always happen in 4.0. Set "Process::inheritEnvironmentVariables()" to true instead.', E_USER_DEPRECATED);
320294
}
295+
296+
$options = array('suppress_errors' => true);
297+
321298
if ('\\' === DIRECTORY_SEPARATOR && $this->enhanceWindowsCompatibility) {
322-
$this->options['bypass_shell'] = true;
299+
$options['bypass_shell'] = true;
323300
$commandline = $this->prepareWindowsCommandLine($commandline, $envBackup, $env);
324301
} elseif (!$this->useFileHandles && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
325302
// last exit code is output on the fourth pipe and caught to work around --enable-sigchild
@@ -334,7 +311,7 @@ public function start(callable $callback = null/*, array $env = array()*/)
334311
$ptsWorkaround = fopen(__FILE__, 'r');
335312
}
336313

337-
$this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $env, $this->options);
314+
$this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $env, $options);
338315

339316
foreach ($envBackup as $k => $v) {
340317
putenv(false === $v ? $k : "$k=$v");
@@ -375,12 +352,11 @@ public function start(callable $callback = null/*, array $env = array()*/)
375352
*
376353
* @final since version 3.3
377354
*/
378-
public function restart(callable $callback = null/*, array $env = array()*/)
355+
public function restart(callable $callback = null, array $env = array())
379356
{
380357
if ($this->isRunning()) {
381358
throw new RuntimeException('Process is already running');
382359
}
383-
$env = 1 < func_num_args() ? func_get_arg(1) : null;
384360

385361
$process = clone $this;
386362
$process->start($callback, $env);
@@ -1178,38 +1154,6 @@ public function setInput($input)
11781154
return $this;
11791155
}
11801156

1181-
/**
1182-
* Gets the options for proc_open.
1183-
*
1184-
* @return array The current options
1185-
*
1186-
* @deprecated since version 3.3, to be removed in 4.0.
1187-
*/
1188-
public function getOptions()
1189-
{
1190-
@trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);
1191-
1192-
return $this->options;
1193-
}
1194-
1195-
/**
1196-
* Sets the options for proc_open.
1197-
*
1198-
* @param array $options The new options
1199-
*
1200-
* @return self The current Process instance
1201-
*
1202-
* @deprecated since version 3.3, to be removed in 4.0.
1203-
*/
1204-
public function setOptions(array $options)
1205-
{
1206-
@trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);
1207-
1208-
$this->options = $options;
1209-
1210-
return $this;
1211-
}
1212-
12131157
/**
12141158
* Gets whether or not Windows compatibility is enabled.
12151159
*
@@ -1290,28 +1234,12 @@ public function setEnhanceSigchildCompatibility($enhance)
12901234
public function inheritEnvironmentVariables($inheritEnv = true)
12911235
{
12921236
if (!$inheritEnv) {
1293-
@trigger_error('Not inheriting environment variables is deprecated since Symfony 3.3 and will always happen in 4.0. Set "Process::inheritEnvironmentVariables()" to true instead.', E_USER_DEPRECATED);
1237+
throw new InvalidArgumentException('Not inheriting environment variables is not supported.');
12941238
}
12951239

1296-
$this->inheritEnv = (bool) $inheritEnv;
1297-
12981240
return $this;
12991241
}
13001242

1301-
/**
1302-
* Returns whether environment variables will be inherited or not.
1303-
*
1304-
* @return bool
1305-
*
1306-
* @deprecated since version 3.3, to be removed in 4.0. Environment variables will always be inherited.
1307-
*/
1308-
public function areEnvironmentVariablesInherited()
1309-
{
1310-
@trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Environment variables will always be inherited.', __METHOD__), E_USER_DEPRECATED);
1311-
1312-
return $this->inheritEnv;
1313-
}
1314-
13151243
/**
13161244
* Performs a check between the timeout definition and the time the process started.
13171245
*

0 commit comments

Comments
 (0)
0