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

Skip to content

[Process] Deprecate Process::setStdin in favor of Process::setInput #10932

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
May 22, 2014
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: 5 additions & 1 deletion UPGRADE-3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -966,4 +966,8 @@ UPGRADE FROM 2.x to 3.0

```
Yaml::parse(file_get_contents($fileName));
```

### Process

* Process::setStdin() and Process::getStdin() have been removed. Use
Process::setInput() and Process::getInput() that works the same way.
2 changes: 2 additions & 0 deletions src/Symfony/Component/Process/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ CHANGELOG

* added support for PTY mode
* added the convenience method "mustRun"
* deprecation: Process::setStdin() is deprecated in favor of Process::setInput()
* deprecation: Process::getStdin() is deprecated in favor of Process::getInput()

2.4.0
-----
Expand Down
50 changes: 41 additions & 9 deletions src/Symfony/Component/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Process
private $commandline;
private $cwd;
private $env;
private $stdin;
private $input;
private $starttime;
private $lastOutputTime;
private $timeout;
Expand Down Expand Up @@ -128,15 +128,15 @@ class Process
* @param string $commandline The command line to run
* @param string|null $cwd The working directory or null to use the working dir of the current PHP process
* @param array|null $env The environment variables or null to inherit
* @param string|null $stdin The STDIN content
* @param string|null $input The input
* @param int|float|null $timeout The timeout in seconds or null to disable
* @param array $options An array of options for proc_open
*
* @throws RuntimeException When proc_open is not installed
*
* @api
*/
public function __construct($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array())
public function __construct($commandline, $cwd = null, array $env = null, $input = null, $timeout = 60, array $options = array())
{
if (!function_exists('proc_open')) {
throw new RuntimeException('The Process class relies on proc_open, which is not available on your PHP installation.');
Expand All @@ -156,7 +156,7 @@ public function __construct($commandline, $cwd = null, array $env = null, $stdin
$this->setEnv($env);
}

$this->stdin = $stdin;
$this->input = $input;
$this->setTimeout($timeout);
$this->useFileHandles = defined('PHP_WINDOWS_VERSION_BUILD');
$this->pty = false;
Expand Down Expand Up @@ -224,7 +224,7 @@ public function mustRun($callback = null)
}

/**
* Starts the process and returns after sending the STDIN.
* Starts the process and returns after writing the input to STDIN.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not always write to stdin anymore, does it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If an input is passed, yes it's written to the underlying process's stdin.

*
* This method blocks until all STDIN data is sent to the process then it
* returns while the process runs in the background.
Expand Down Expand Up @@ -288,7 +288,7 @@ public function start($callback = null)
return;
}

$this->processPipes->write(false, $this->stdin);
$this->processPipes->write(false, $this->input);
$this->updateStatus(false);
$this->checkTimeout();
}
Expand Down Expand Up @@ -1038,10 +1038,23 @@ public function setEnv(array $env)
* Gets the contents of STDIN.
*
* @return string|null The current contents
*
* @deprecated Deprecated since version 2.5, to be removed in 3.0.
* This method is deprecated in favor of getInput.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we throw a deprecated error?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope. We will only add the deprecation warning in the last minor version of Symfony before 3.0, like everywhere else

public function getStdin()
{
return $this->stdin;
return $this->getInput();
}

/**
* Gets the Process input.
*
* @return null|string The Process input
*/
public function getInput()
{
return $this->input;
}

/**
Expand All @@ -1052,14 +1065,33 @@ public function getStdin()
* @return self The current Process instance
*
* @throws LogicException In case the process is running
*
* @deprecated Deprecated since version 2.5, to be removed in 3.0.
* This method is deprecated in favor of setInput.
*/
public function setStdin($stdin)
{
return $this->setInput($stdin);
}

/**
* Sets the input.
*
* This content will be passed to the underlying process standard input.
*
* @param string|null $input The content
*
* @return self The current Process instance
*
* @throws LogicException In case the process is running
*/
public function setInput($input)
{
if ($this->isRunning()) {
throw new LogicException('STDIN can not be set while the process is running.');
throw new LogicException('Input can not be set while the process is running.');
}

$this->stdin = $stdin;
$this->input = $input;

return $this;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/Process/ProcessBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ProcessBuilder
private $arguments;
private $cwd;
private $env = array();
private $stdin;
private $input;
private $timeout = 60;
private $options = array();
private $inheritEnv = true;
Expand Down Expand Up @@ -156,13 +156,13 @@ public function addEnvironmentVariables(array $variables)
/**
* Sets the input of the process.
*
* @param string $stdin The input as a string
* @param string $input The input as a string
*
* @return ProcessBuilder
*/
public function setInput($stdin)
public function setInput($input)
{
$this->stdin = $stdin;
$this->input = $input;

return $this;
}
Expand Down Expand Up @@ -261,7 +261,7 @@ public function getProcess()
$env = $this->env;
}

$process = new Process($script, $this->cwd, $env, $this->stdin, $this->timeout, $options);
$process = new Process($script, $this->cwd, $env, $this->input, $this->timeout, $options);

if ($this->outputDisabled) {
$process->disableOutput();
Expand Down
23 changes: 12 additions & 11 deletions src/Symfony/Component/Process/Tests/AbstractProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,23 +151,23 @@ public function testProcessPipes($code, $size)
$expectedLength = (1024 * $size) + 1;

$p = $this->getProcess(sprintf('php -r %s', escapeshellarg($code)));
$p->setStdin($expected);
$p->setInput($expected);
$p->run();

$this->assertEquals($expectedLength, strlen($p->getOutput()));
$this->assertEquals($expectedLength, strlen($p->getErrorOutput()));
}

public function testSetStdinWhileRunningThrowsAnException()
public function testSetInputWhileRunningThrowsAnException()
{
$process = $this->getProcess('php -r "usleep(500000);"');
$process->start();
try {
$process->setStdin('foobar');
$process->setInput('foobar');
$process->stop();
$this->fail('A LogicException should have been raised.');
} catch (LogicException $e) {
$this->assertEquals('STDIN can not be set while the process is running.', $e->getMessage());
$this->assertEquals('Input can not be set while the process is running.', $e->getMessage());
}
$process->stop();
}
Expand Down Expand Up @@ -993,21 +993,22 @@ public function methodProvider()
array('WorkingDirectory'),
array('Env'),
array('Stdin'),
array('Input'),
array('Options')
);

return $defaults;
}

/**
* @param string $commandline
* @param null $cwd
* @param array $env
* @param null $stdin
* @param int $timeout
* @param array $options
* @param string $commandline
* @param null|string $cwd
* @param null|array $env
* @param null|string $input
* @param int $timeout
* @param array $options
*
* @return Process
*/
abstract protected function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array());
abstract protected function getProcess($commandline, $cwd = null, array $env = null, $input = null, $timeout = 60, array $options = array());
}
4 changes: 2 additions & 2 deletions src/Symfony/Component/Process/Tests/SimpleProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ public function testSignalWithWrongNonIntSignal()
/**
* {@inheritdoc}
*/
protected function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array())
protected function getProcess($commandline, $cwd = null, array $env = null, $input = null, $timeout = 60, array $options = array())
{
return new Process($commandline, $cwd, $env, $stdin, $timeout, $options);
return new Process($commandline, $cwd, $env, $input, $timeout, $options);
}

private function skipIfPHPSigchild()
Expand Down