Skip to content

Commit

Permalink
Make PrettyPageHandler more easily extendable (filp#517)
Browse files Browse the repository at this point in the history
separate code and frames extraction
  • Loading branch information
juliangut authored and denis-sokolov committed Aug 3, 2017
1 parent 324905f commit ffbbd2c
Showing 1 changed file with 43 additions and 21 deletions.
64 changes: 43 additions & 21 deletions src/Whoops/Handler/PrettyPageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,27 +176,8 @@ public function handle()
}

$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 = [
Expand Down Expand Up @@ -268,6 +249,47 @@ public function handle()
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
*/
Expand Down

0 comments on commit ffbbd2c

Please sign in to comment.