[Process] Fix docblocks, remove return
from PhpProcess#start()
as parent returns nothing, cleaned up ExecutableFinder
This commit is contained in:
parent
92f951fd7a
commit
a62e04f8d1
@ -19,22 +19,23 @@ namespace Symfony\Component\Process;
|
|||||||
*/
|
*/
|
||||||
class ExecutableFinder
|
class ExecutableFinder
|
||||||
{
|
{
|
||||||
private static $isWindows;
|
|
||||||
|
|
||||||
private $suffixes = array('.exe', '.bat', '.cmd', '.com');
|
private $suffixes = array('.exe', '.bat', '.cmd', '.com');
|
||||||
|
|
||||||
public function __construct()
|
/**
|
||||||
{
|
* Replaces default suffixes of executable.
|
||||||
if (null === self::$isWindows) {
|
*
|
||||||
self::$isWindows = 0 === stripos(PHP_OS, 'win');
|
* @param array $suffixes
|
||||||
}
|
*/
|
||||||
}
|
|
||||||
|
|
||||||
public function setSuffixes(array $suffixes)
|
public function setSuffixes(array $suffixes)
|
||||||
{
|
{
|
||||||
$this->suffixes = $suffixes;
|
$this->suffixes = $suffixes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds new possible suffix to check for executable.
|
||||||
|
*
|
||||||
|
* @param string $suffix
|
||||||
|
*/
|
||||||
public function addSuffix($suffix)
|
public function addSuffix($suffix)
|
||||||
{
|
{
|
||||||
$this->suffixes[] = $suffix;
|
$this->suffixes[] = $suffix;
|
||||||
@ -78,7 +79,7 @@ class ExecutableFinder
|
|||||||
}
|
}
|
||||||
foreach ($suffixes as $suffix) {
|
foreach ($suffixes as $suffix) {
|
||||||
foreach ($dirs as $dir) {
|
foreach ($dirs as $dir) {
|
||||||
if (is_file($file = $dir.DIRECTORY_SEPARATOR.$name.$suffix) && (self::$isWindows || is_executable($file))) {
|
if (is_file($file = $dir.DIRECTORY_SEPARATOR.$name.$suffix) && (defined('PHP_WINDOWS_VERSION_BUILD') || is_executable($file))) {
|
||||||
return $file;
|
return $file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,6 +66,6 @@ class PhpProcess extends Process
|
|||||||
$this->setCommandLine($php);
|
$this->setCommandLine($php);
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::start($callback);
|
parent::start($callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,7 @@ class Process
|
|||||||
* The STDOUT and STDERR are also available after the process is finished
|
* The STDOUT and STDERR are also available after the process is finished
|
||||||
* via the getOutput() and getErrorOutput() methods.
|
* via the getOutput() and getErrorOutput() methods.
|
||||||
*
|
*
|
||||||
* @param Closure|string|array $callback A PHP callback to run whenever there is some
|
* @param callback|null $callback A PHP callback to run whenever there is some
|
||||||
* output available on STDOUT or STDERR
|
* output available on STDOUT or STDERR
|
||||||
*
|
*
|
||||||
* @return integer The exit status code
|
* @return integer The exit status code
|
||||||
@ -190,7 +190,7 @@ class Process
|
|||||||
* with true as a second parameter then the callback will get all data occurred
|
* with true as a second parameter then the callback will get all data occurred
|
||||||
* in (and since) the start call.
|
* in (and since) the start call.
|
||||||
*
|
*
|
||||||
* @param Closure|string|array $callback A PHP callback to run whenever there is some
|
* @param callback|null $callback A PHP callback to run whenever there is some
|
||||||
* output available on STDOUT or STDERR
|
* output available on STDOUT or STDERR
|
||||||
*
|
*
|
||||||
* @throws \RuntimeException When process can't be launch or is stopped
|
* @throws \RuntimeException When process can't be launch or is stopped
|
||||||
@ -318,11 +318,12 @@ class Process
|
|||||||
* from the output in real-time while writing the standard input to the process.
|
* from the output in real-time while writing the standard input to the process.
|
||||||
* It allows to have feedback from the independent process during execution.
|
* It allows to have feedback from the independent process during execution.
|
||||||
*
|
*
|
||||||
* @param mixed $callback A valid PHP callback
|
* @param callback|null $callback A valid PHP callback
|
||||||
*
|
*
|
||||||
* @return int The exitcode of the process
|
* @return integer The exitcode of the process
|
||||||
*
|
*
|
||||||
* @throws \RuntimeException
|
* @throws \RuntimeException When process timed out
|
||||||
|
* @throws \RuntimeException When process stopped after receiving signal
|
||||||
*/
|
*/
|
||||||
public function wait($callback = null)
|
public function wait($callback = null)
|
||||||
{
|
{
|
||||||
@ -455,8 +456,6 @@ class Process
|
|||||||
*
|
*
|
||||||
* @return string A string representation for the exit status code
|
* @return string A string representation for the exit status code
|
||||||
*
|
*
|
||||||
* @throws RuntimeException In case --enable-sigchild is activated and the sigchild compatibility mode is disabled
|
|
||||||
*
|
|
||||||
* @see http://tldp.org/LDP/abs/html/exitcodes.html
|
* @see http://tldp.org/LDP/abs/html/exitcodes.html
|
||||||
* @see http://en.wikipedia.org/wiki/Unix_signal
|
* @see http://en.wikipedia.org/wiki/Unix_signal
|
||||||
*/
|
*/
|
||||||
@ -472,8 +471,6 @@ class Process
|
|||||||
*
|
*
|
||||||
* @return Boolean true if the process ended successfully, false otherwise
|
* @return Boolean true if the process ended successfully, false otherwise
|
||||||
*
|
*
|
||||||
* @throws RuntimeException In case --enable-sigchild is activated and the sigchild compatibility mode is disabled
|
|
||||||
*
|
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
public function isSuccessful()
|
public function isSuccessful()
|
||||||
@ -576,11 +573,9 @@ class Process
|
|||||||
/**
|
/**
|
||||||
* Stops the process.
|
* Stops the process.
|
||||||
*
|
*
|
||||||
* @param float $timeout The timeout in seconds
|
* @param integer|float $timeout The timeout in seconds
|
||||||
*
|
*
|
||||||
* @return integer The exit-code of the process
|
* @return integer The exit-code of the process
|
||||||
*
|
|
||||||
* @throws \RuntimeException if the process got signaled
|
|
||||||
*/
|
*/
|
||||||
public function stop($timeout=10)
|
public function stop($timeout=10)
|
||||||
{
|
{
|
||||||
@ -828,9 +823,9 @@ class Process
|
|||||||
* The callbacks adds all occurred output to the specific buffer and calls
|
* The callbacks adds all occurred output to the specific buffer and calls
|
||||||
* the user callback (if present) with the received output.
|
* the user callback (if present) with the received output.
|
||||||
*
|
*
|
||||||
* @param mixed $callback The user defined PHP callback
|
* @param callback|null $callback The user defined PHP callback
|
||||||
*
|
*
|
||||||
* @return mixed A PHP callable
|
* @return callback A PHP callable
|
||||||
*/
|
*/
|
||||||
protected function buildCallback($callback)
|
protected function buildCallback($callback)
|
||||||
{
|
{
|
||||||
@ -870,6 +865,9 @@ class Process
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the current error output of the process (STDERR).
|
||||||
|
*/
|
||||||
protected function updateErrorOutput()
|
protected function updateErrorOutput()
|
||||||
{
|
{
|
||||||
if (isset($this->pipes[self::STDERR]) && is_resource($this->pipes[self::STDERR])) {
|
if (isset($this->pipes[self::STDERR]) && is_resource($this->pipes[self::STDERR])) {
|
||||||
@ -877,6 +875,9 @@ class Process
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the current output of the process (STDOUT).
|
||||||
|
*/
|
||||||
protected function updateOutput()
|
protected function updateOutput()
|
||||||
{
|
{
|
||||||
if (defined('PHP_WINDOWS_VERSION_BUILD') && isset($this->fileHandles[self::STDOUT]) && is_resource($this->fileHandles[self::STDOUT])) {
|
if (defined('PHP_WINDOWS_VERSION_BUILD') && isset($this->fileHandles[self::STDOUT]) && is_resource($this->fileHandles[self::STDOUT])) {
|
||||||
|
@ -16,8 +16,6 @@ namespace Symfony\Component\Process\Tests;
|
|||||||
*/
|
*/
|
||||||
abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
|
abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
abstract protected function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array());
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \InvalidArgumentException
|
* @expectedException \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
@ -300,4 +298,16 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
return $defaults;
|
return $defaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $commandline
|
||||||
|
* @param null $cwd
|
||||||
|
* @param array $env
|
||||||
|
* @param null $stdin
|
||||||
|
* @param integer $timeout
|
||||||
|
* @param array $options
|
||||||
|
*
|
||||||
|
* @return \Symfony\Component\Process\Process
|
||||||
|
*/
|
||||||
|
abstract protected function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array());
|
||||||
}
|
}
|
||||||
|
@ -13,15 +13,6 @@ namespace Symfony\Component\Process\Tests;
|
|||||||
|
|
||||||
class SigchildDisabledProcessTest extends AbstractProcessTest
|
class SigchildDisabledProcessTest extends AbstractProcessTest
|
||||||
{
|
{
|
||||||
|
|
||||||
protected function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array())
|
|
||||||
{
|
|
||||||
$process = new ProcessInSigchildEnvironment($commandline, $cwd, $env, $stdin, $timeout, $options);
|
|
||||||
$process->setEnhanceSigchildCompatibility(false);
|
|
||||||
|
|
||||||
return $process;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Symfony\Component\Process\Exception\RuntimeException
|
* @expectedException Symfony\Component\Process\Exception\RuntimeException
|
||||||
*/
|
*/
|
||||||
@ -96,4 +87,15 @@ class SigchildDisabledProcessTest extends AbstractProcessTest
|
|||||||
{
|
{
|
||||||
parent::testIsNotSuccessful();
|
parent::testIsNotSuccessful();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array())
|
||||||
|
{
|
||||||
|
$process = new ProcessInSigchildEnvironment($commandline, $cwd, $env, $stdin, $timeout, $options);
|
||||||
|
$process->setEnhanceSigchildCompatibility(false);
|
||||||
|
|
||||||
|
return $process;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,15 +13,6 @@ namespace Symfony\Component\Process\Tests;
|
|||||||
|
|
||||||
class SigchildEnabledProcessTest extends AbstractProcessTest
|
class SigchildEnabledProcessTest extends AbstractProcessTest
|
||||||
{
|
{
|
||||||
|
|
||||||
protected function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array())
|
|
||||||
{
|
|
||||||
$process = new ProcessInSigchildEnvironment($commandline, $cwd, $env, $stdin, $timeout, $options);
|
|
||||||
$process->setEnhanceSigchildCompatibility(true);
|
|
||||||
|
|
||||||
return $process;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Symfony\Component\Process\Exception\RuntimeException
|
* @expectedException Symfony\Component\Process\Exception\RuntimeException
|
||||||
*/
|
*/
|
||||||
@ -62,4 +53,14 @@ class SigchildEnabledProcessTest extends AbstractProcessTest
|
|||||||
$this->assertInternalType('string', $process->getExitCodeText());
|
$this->assertInternalType('string', $process->getExitCodeText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array())
|
||||||
|
{
|
||||||
|
$process = new ProcessInSigchildEnvironment($commandline, $cwd, $env, $stdin, $timeout, $options);
|
||||||
|
$process->setEnhanceSigchildCompatibility(true);
|
||||||
|
|
||||||
|
return $process;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,20 +15,14 @@ use Symfony\Component\Process\Process;
|
|||||||
|
|
||||||
class SimpleProcessTest extends AbstractProcessTest
|
class SimpleProcessTest extends AbstractProcessTest
|
||||||
{
|
{
|
||||||
|
private $enabledSigchild = false;
|
||||||
|
|
||||||
protected function skipIfPHPSigchild()
|
public function setUp()
|
||||||
{
|
{
|
||||||
ob_start();
|
ob_start();
|
||||||
phpinfo(INFO_GENERAL);
|
phpinfo(INFO_GENERAL);
|
||||||
|
|
||||||
if (false !== strpos(ob_get_clean(), '--enable-sigchild')) {
|
$this->enabledSigchild = false !== strpos(ob_get_clean(), '--enable-sigchild');
|
||||||
$this->markTestSkipped('Your PHP has been compiled with --enable-sigchild, this test can not be executed');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array())
|
|
||||||
{
|
|
||||||
return new Process($commandline, $cwd, $env, $stdin, $timeout, $options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetExitCode()
|
public function testGetExitCode()
|
||||||
@ -84,4 +78,19 @@ class SimpleProcessTest extends AbstractProcessTest
|
|||||||
$this->skipIfPHPSigchild();
|
$this->skipIfPHPSigchild();
|
||||||
parent::testIsNotSuccessful();
|
parent::testIsNotSuccessful();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array())
|
||||||
|
{
|
||||||
|
return new Process($commandline, $cwd, $env, $stdin, $timeout, $options);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function skipIfPHPSigchild()
|
||||||
|
{
|
||||||
|
if ($this->enabledSigchild) {
|
||||||
|
$this->markTestSkipped('Your PHP has been compiled with --enable-sigchild, this test can not be executed');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user