Skip to content

Commit

Permalink
minor #10756 [2.3][Process] Add missing docblocks, remove variable de…
Browse files Browse the repository at this point in the history
…clarations (romainneutron)

This PR was merged into the 2.3 branch.

Discussion
----------

[2.3][Process] Add missing docblocks, remove variable declarations

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT

Commits
-------

ff77f24 [Process] Add missing docblocks, remove variable declarations
  • Loading branch information
fabpot committed Apr 23, 2014
2 parents 1ad7d05 + ff77f24 commit 5947eec
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 18 deletions.
11 changes: 4 additions & 7 deletions src/Symfony/Component/Process/Process.php
Expand Up @@ -52,7 +52,7 @@ class Process
private $processInformation;
private $stdout;
private $stderr;
private $enhanceWindowsCompatibility;
private $enhanceWindowsCompatibility = true;
private $enhanceSigchildCompatibility;
private $process;
private $status = self::STATUS_READY;
Expand Down Expand Up @@ -143,19 +143,16 @@ public function __construct($commandline, $cwd = null, array $env = null, $stdin
// on Gnu/Linux, PHP builds with --enable-maintainer-zts are also affected
// @see : https://bugs.php.net/bug.php?id=51800
// @see : https://bugs.php.net/bug.php?id=50524

if (null === $this->cwd && (defined('ZEND_THREAD_SAFE') || defined('PHP_WINDOWS_VERSION_BUILD'))) {
$this->cwd = getcwd();
}
if (null !== $env) {
$this->setEnv($env);
} else {
$this->env = null;
}

$this->stdin = $stdin;
$this->setTimeout($timeout);
$this->useFileHandles = defined('PHP_WINDOWS_VERSION_BUILD');
$this->enhanceWindowsCompatibility = true;
$this->enhanceSigchildCompatibility = !defined('PHP_WINDOWS_VERSION_BUILD') && $this->isSigchildEnabled();
$this->options = array_replace(array('suppress_errors' => true, 'binary_pipes' => true), $options);
}
Expand Down Expand Up @@ -1203,7 +1200,7 @@ private function doSignal($signal, $throwException)
/**
* Ensures the process is running or terminated, throws a LogicException if the process has a not started.
*
* @param $functionName The function name that was called.
* @param string $functionName The function name that was called.
*
* @throws LogicException If the process has not run.
*/
Expand All @@ -1217,7 +1214,7 @@ private function requireProcessIsStarted($functionName)
/**
* Ensures the process is terminated, throws a LogicException if the process has a status different than `terminated`.
*
* @param $functionName The function name that was called.
* @param string $functionName The function name that was called.
*
* @throws LogicException If the process is not yet terminated.
*/
Expand Down
81 changes: 70 additions & 11 deletions src/Symfony/Component/Process/ProcessBuilder.php
Expand Up @@ -23,23 +23,30 @@ class ProcessBuilder
{
private $arguments;
private $cwd;
private $env;
private $env = array();
private $stdin;
private $timeout;
private $options;
private $inheritEnv;
private $timeout = 60;
private $options = array();
private $inheritEnv = true;
private $prefix;

/**
* Constructor
*
* @param string[] $arguments An array of arguments
*/
public function __construct(array $arguments = array())
{
$this->arguments = $arguments;

$this->timeout = 60;
$this->options = array();
$this->env = array();
$this->inheritEnv = true;
}

/**
* Creates a process builder instance.
*
* @param string[] $arguments An array of arguments
*
* @return ProcessBuilder
*/
public static function create(array $arguments = array())
{
return new static($arguments);
Expand All @@ -62,7 +69,7 @@ public function add($argument)
/**
* Adds an unescaped prefix to the command string.
*
* The prefix is preserved when reseting arguments.
* The prefix is preserved when resetting arguments.
*
* @param string $prefix A command prefix
*
Expand All @@ -76,7 +83,12 @@ public function setPrefix($prefix)
}

/**
* @param array $arguments
* Sets the arguments of the process.
*
* Arguments must not be escaped.
* Previous arguments are removed.
*
* @param string[] $arguments
*
* @return ProcessBuilder
*/
Expand All @@ -87,27 +99,59 @@ public function setArguments(array $arguments)
return $this;
}

/**
* Sets the working directory.
*
* @param null|string $cwd The working directory
*
* @return ProcessBuilder
*/
public function setWorkingDirectory($cwd)
{
$this->cwd = $cwd;

return $this;
}

/**
* Sets whether environment variables will be inherited or not.
*
* @param bool $inheritEnv
*
* @return ProcessBuilder
*/
public function inheritEnvironmentVariables($inheritEnv = true)
{
$this->inheritEnv = $inheritEnv;

return $this;
}

/**
* Sets an environment variable
*
* Setting a variable overrides its previous value. Use `null` to unset a
* defined environment variable.
*
* @param string $name The variable name
* @param null|string $value The variable value
*
* @return ProcessBuilder
*/
public function setEnv($name, $value)
{
$this->env[$name] = $value;

return $this;
}

/**
* Sets the input of the process.
*
* @param string $stdin The input as a string
*
* @return ProcessBuilder
*/
public function setInput($stdin)
{
$this->stdin = $stdin;
Expand Down Expand Up @@ -145,13 +189,28 @@ public function setTimeout($timeout)
return $this;
}

/**
* Adds a proc_open option.
*
* @param string $name The option name
* @param string $value The option value
*
* @return ProcessBuilder
*/
public function setOption($name, $value)
{
$this->options[$name] = $value;

return $this;
}

/**
* Creates a Process instance and returns it.
*
* @return Process
*
* @throws LogicException In case no arguments have been provided
*/
public function getProcess()
{
if (!$this->prefix && !count($this->arguments)) {
Expand Down

0 comments on commit 5947eec

Please sign in to comment.