merged branch Tobion/console-status-code (PR #8202)
This PR was merged into the 2.1 branch. Discussion ---------- [Console] fix status and exit code Fix https://github.com/symfony/symfony/pull/8183#discussion_r4525267 and http://www.php.net/manual/en/function.exit.php > Exit statuses should be in the range 0 to 254, the exit status 255 is reserved by PHP and shall not be used. The status 0 is used to terminate the program successfully. Commits -------6b9180a
[Console] ensure exit code between 0-254445b2e3
[Console] fix status code when Exception::getCode returns something like 0.1
This commit is contained in:
commit
82e555263f
@ -113,17 +113,22 @@ class Application
|
|||||||
} else {
|
} else {
|
||||||
$this->renderException($e, $output);
|
$this->renderException($e, $output);
|
||||||
}
|
}
|
||||||
$statusCode = $e->getCode();
|
|
||||||
|
|
||||||
$statusCode = is_numeric($statusCode) && $statusCode ? (int) $statusCode : 1;
|
$statusCode = $e->getCode();
|
||||||
|
if (is_numeric($statusCode)) {
|
||||||
|
$statusCode = (int) $statusCode;
|
||||||
|
if (0 === $statusCode) {
|
||||||
|
$statusCode = 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$statusCode = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->autoExit) {
|
if ($this->autoExit) {
|
||||||
if ($statusCode > 255) {
|
// ensure exit code is between 0-254 (255 is reserved by PHP and should not be used)
|
||||||
$statusCode = 255;
|
|
||||||
}
|
|
||||||
// @codeCoverageIgnoreStart
|
// @codeCoverageIgnoreStart
|
||||||
exit($statusCode);
|
exit(max(0, min(254, $statusCode)));
|
||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user