[Process] added Process::getExitCodeText() (closes #2818)
This commit is contained in:
parent
11179c2201
commit
b80951c21c
@ -35,6 +35,54 @@ class Process
|
||||
private $stdout;
|
||||
private $stderr;
|
||||
|
||||
/**
|
||||
* Exit codes translation table.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static public $exitCodes = array(
|
||||
0 => 'OK',
|
||||
1 => 'General error',
|
||||
2 => 'Misuse of shell builtins',
|
||||
|
||||
126 => 'Invoked command cannot execute',
|
||||
127 => 'Command not found',
|
||||
128 => 'Invalid exit argument',
|
||||
|
||||
// signals
|
||||
129 => 'Hangup',
|
||||
130 => 'Interrupt',
|
||||
131 => 'Quit and dump core',
|
||||
132 => 'Illegal instruction',
|
||||
133 => 'Trace/breakpoint trap',
|
||||
134 => 'Process aborted',
|
||||
135 => 'Bus error: "access to undefined portion of memory object"',
|
||||
136 => 'Floating point exception: "erroneous arithmetic operation"',
|
||||
137 => 'Kill (terminate immediately)',
|
||||
138 => 'User-defined 1',
|
||||
139 => 'Segmentation violation',
|
||||
140 => 'User-defined 2',
|
||||
141 => 'Write to pipe with no one reading',
|
||||
142 => 'Signal raised by alarm',
|
||||
143 => 'Termination (request to terminate)',
|
||||
// 144 - not defined
|
||||
145 => 'Child process terminated, stopped (or continued*)',
|
||||
146 => 'Continue if stopped',
|
||||
147 => 'Stop executing temporarily',
|
||||
148 => 'Terminal stop signal',
|
||||
149 => 'Background process attempting to read from tty ("in")',
|
||||
150 => 'Background process attempting to write to tty ("out")',
|
||||
151 => 'Urgent data available on socket',
|
||||
152 => 'CPU time limit exceeded',
|
||||
153 => 'File size limit exceeded',
|
||||
154 => 'Signal raised by timer counting virtual time: "virtual timer expired"',
|
||||
155 => 'Profiling timer expired',
|
||||
// 156 - not defined
|
||||
157 => 'Pollable event',
|
||||
// 158 - not defined
|
||||
159 => 'Bad syscall',
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@ -230,6 +278,22 @@ class Process
|
||||
return $this->exitcode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation for the exit code returned by the process.
|
||||
*
|
||||
* This method relies on the Unix exit code status standardization
|
||||
* and might not be relevant for other operating systems.
|
||||
*
|
||||
* @return string A string representation for the exit status code
|
||||
*
|
||||
* @see http://tldp.org/LDP/abs/html/exitcodes.html
|
||||
* @see http://en.wikipedia.org/wiki/Unix_signal
|
||||
*/
|
||||
public function getExitCodeText()
|
||||
{
|
||||
return isset(self::$exitCodes[$this->exitcode]) ? self::$exitCodes[$this->exitcode] : 'Unknown error';
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the process ended successfully.
|
||||
*
|
||||
|
@ -68,6 +68,17 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(0, $p->getExitCode());
|
||||
}
|
||||
|
||||
public function testExitCodeText()
|
||||
{
|
||||
$process = new Process('');
|
||||
$r = new \ReflectionObject($process);
|
||||
$p = $r->getProperty('exitcode');
|
||||
$p->setAccessible(true);
|
||||
|
||||
$p->setValue($process, 2);
|
||||
$this->assertEquals('Misuse of shell builtins', $process->getExitCodeText());
|
||||
}
|
||||
|
||||
public function responsesCodeProvider()
|
||||
{
|
||||
return array(
|
||||
|
Reference in New Issue
Block a user