mirror of
https://github.com/filp/whoops.git
synced 2026-08-31 12:38:10 +00:00
Make PrettyPageHandler more easily extendable (#517)
separate code and frames extraction
This commit is contained in:
committed by
Denis Sokolov
parent
324905f307
commit
ffbbd2c06c
@@ -176,27 +176,8 @@ class PrettyPageHandler extends Handler
|
||||
}
|
||||
|
||||
$inspector = $this->getInspector();
|
||||
$frames = $inspector->getFrames();
|
||||
|
||||
$code = $inspector->getException()->getCode();
|
||||
|
||||
if ($inspector->getException() instanceof \ErrorException) {
|
||||
// ErrorExceptions wrap the php-error types within the "severity" property
|
||||
$code = Misc::translateErrorCode($inspector->getException()->getSeverity());
|
||||
}
|
||||
|
||||
// Detect frames that belong to the application.
|
||||
if ($this->applicationPaths) {
|
||||
/* @var \Whoops\Exception\Frame $frame */
|
||||
foreach ($frames as $frame) {
|
||||
foreach ($this->applicationPaths as $path) {
|
||||
if (substr($frame->getFile(), 0, strlen($path)) === $path) {
|
||||
$frame->setApplication(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$frames = $this->getExceptionFrames();
|
||||
$code = $this->getExceptionCode();
|
||||
|
||||
// List of variables that will be passed to the layout template.
|
||||
$vars = [
|
||||
@@ -268,6 +249,47 @@ class PrettyPageHandler extends Handler
|
||||
return Handler::QUIT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the stack trace frames of the exception that is currently being handled.
|
||||
*
|
||||
* @return \Whoops\Exception\FrameCollection;
|
||||
*/
|
||||
protected function getExceptionFrames()
|
||||
{
|
||||
$frames = $this->getInspector()->getFrames();
|
||||
|
||||
if ($this->getApplicationPaths()) {
|
||||
foreach ($frames as $frame) {
|
||||
foreach ($this->getApplicationPaths() as $path) {
|
||||
if (strpos($frame->getFile(), $path) === 0) {
|
||||
$frame->setApplication(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $frames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the code of the exception that is currently being handled.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getExceptionCode()
|
||||
{
|
||||
$exception = $this->getException();
|
||||
|
||||
$code = $exception->getCode();
|
||||
if ($exception instanceof \ErrorException) {
|
||||
// ErrorExceptions wrap the php-error types within the 'severity' property
|
||||
$code = Misc::translateErrorCode($exception->getSeverity());
|
||||
}
|
||||
|
||||
return (string) $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user