[Process] Add missing docblocks, remove variable declarations

This commit is contained in:
Romain Neutron 2014-04-21 19:54:45 +02:00
parent ba55b1ed18
commit ff77f24092
2 changed files with 74 additions and 18 deletions

View File

@ -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;
@ -143,19 +143,16 @@ class Process
// 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);
}
@ -1197,7 +1194,7 @@ class Process
/**
* 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.
*/
@ -1211,7 +1208,7 @@ class Process
/**
* 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.
*/

View File

@ -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);
@ -62,7 +69,7 @@ class ProcessBuilder
/**
* 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
*
@ -76,7 +83,12 @@ class ProcessBuilder
}
/**
* @param array $arguments
* Sets the arguments of the process.
*
* Arguments must not be escaped.
* Previous arguments are removed.
*
* @param string[] $arguments
*
* @return ProcessBuilder
*/
@ -87,6 +99,13 @@ class ProcessBuilder
return $this;
}
/**
* Sets the working directory.
*
* @param null|string $cwd The working directory
*
* @return ProcessBuilder
*/
public function setWorkingDirectory($cwd)
{
$this->cwd = $cwd;
@ -94,6 +113,13 @@ class ProcessBuilder
return $this;
}
/**
* Sets whether environment variables will be inherited or not.
*
* @param bool $inheritEnv
*
* @return ProcessBuilder
*/
public function inheritEnvironmentVariables($inheritEnv = true)
{
$this->inheritEnv = $inheritEnv;
@ -101,6 +127,17 @@ class ProcessBuilder
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;
@ -108,6 +145,13 @@ class ProcessBuilder
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;
@ -145,6 +189,14 @@ class ProcessBuilder
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;
@ -152,6 +204,13 @@ class ProcessBuilder
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)) {