-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,11 @@ class Whoops implements MiddlewareInterface | |
*/ | ||
private $whoops; | ||
|
||
/** | ||
* @var SystemFacade|null | ||
*/ | ||
private $system; | ||
|
||
/** | ||
* @var bool Whether catch errors or not | ||
*/ | ||
|
@@ -29,10 +34,12 @@ class Whoops implements MiddlewareInterface | |
* Set the whoops instance. | ||
* | ||
* @param Run|null $whoops | ||
* @param SystemFacade|null $systemFacade | ||
*/ | ||
public function __construct(Run $whoops = null) | ||
public function __construct(Run $whoops = null, SystemFacade $system = null) | ||
{ | ||
$this->whoops = $whoops; | ||
$this->system = $system; | ||
} | ||
|
||
/** | ||
|
@@ -63,7 +70,7 @@ public function process(ServerRequestInterface $request, DelegateInterface $dele | |
$level = ob_get_level(); | ||
|
||
$method = Run::EXCEPTION_HANDLER; | ||
$whoops = $this->whoops ?: self::getWhoopsInstance($request); | ||
$whoops = $this->whoops ?: $this->getWhoopsInstance($request); | ||
|
||
$whoops->allowQuit(false); | ||
$whoops->writeToOutput(false); | ||
|
@@ -72,6 +79,21 @@ public function process(ServerRequestInterface $request, DelegateInterface $dele | |
//Catch errors means register whoops globally | ||
if ($this->catchErrors) { | ||
$whoops->register(); | ||
|
||
$shutdown = function () use ($whoops) { | ||
$whoops->allowQuit(true); | ||
$whoops->writeToOutput(true); | ||
$whoops->sendHttpCode(true); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
oscarotero
Author
Member
|
||
|
||
$method = Run::SHUTDOWN_HANDLER; | ||
$whoops->$method(); | ||
}; | ||
|
||
if ($this->system) { | ||
$this->system->registerShutdownFunction($shutdown); | ||
} else { | ||
register_shutdown_function($shutdown); | ||
} | ||
} | ||
|
||
try { | ||
|
@@ -104,23 +126,14 @@ public function process(ServerRequestInterface $request, DelegateInterface $dele | |
* | ||
* @return Run | ||
*/ | ||
private static function getWhoopsInstance(ServerRequestInterface $request) | ||
private function getWhoopsInstance(ServerRequestInterface $request) | ||
{ | ||
$system = new SystemFacade(); | ||
$whoops = new Run($system); | ||
|
||
//E_ERROR in PHP 5.x | ||
if (!class_exists('Throwable')) { | ||
$system->registerShutdownFunction(function () use ($whoops) { | ||
$whoops->allowQuit(true); | ||
$whoops->writeToOutput(true); | ||
$whoops->sendHttpCode(true); | ||
|
||
$method = Run::SHUTDOWN_HANDLER; | ||
$whoops->$method(); | ||
}); | ||
if (!$this->system) { | ||
$this->system = new SystemFacade(); | ||
} | ||
|
||
$whoops = new Run($this->system); | ||
|
||
switch (self::getPreferredFormat($request)) { | ||
case 'json': | ||
$handler = new JsonResponseHandler(); | ||
|
1 comment
on commit 99bab7b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shadowhand Implemented the option "b" (passing the SystemFacade
to the constructor) and option "c" (execute register_shutdown_function
directly) as fallback.
I think
allowQuit
andsendHttpCode
would still need to befalse
to properly capture the error, no?