mirror of
https://github.com/filp/whoops.git
synced 2026-08-30 20:17:11 +00:00
Improve how script termination is handled
This commit is contained in:
@@ -22,6 +22,7 @@ class Handler implements HandlerInterface
|
||||
* to message the handler walker.
|
||||
*/
|
||||
const LAST_HANDLER = 0x10;
|
||||
const QUIT = 0x20;
|
||||
|
||||
/**
|
||||
* @var Damnit\Run
|
||||
|
||||
@@ -41,7 +41,7 @@ class PrettyPageHandler extends Handler
|
||||
// Prepare the $v global variable that will pass relevant
|
||||
// information to the template
|
||||
$inspector = $this->getInspector();
|
||||
$frames = $inspector->getFrames();
|
||||
$frames = $inspector->getFrames();
|
||||
|
||||
$v = (object) array(
|
||||
'name' => explode('\\', $inspector->getExceptionName()),
|
||||
@@ -79,7 +79,8 @@ class PrettyPageHandler extends Handler
|
||||
require $templateFile;
|
||||
});
|
||||
|
||||
return Handler::LAST_HANDLER;
|
||||
|
||||
return Handler::QUIT;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+17
-13
@@ -20,7 +20,7 @@ class Run
|
||||
const SHUTDOWN_HANDLER = 'handleShutdown';
|
||||
|
||||
protected $isRegistered;
|
||||
protected $exitWhenDone = true;
|
||||
protected $allowQuit = true;
|
||||
|
||||
/**
|
||||
* @var DarnIt\Handler\HandlerInterface[]
|
||||
@@ -123,14 +123,12 @@ class Run
|
||||
}
|
||||
|
||||
/**
|
||||
* Should Damnit quit the script once all handlers have executed?
|
||||
* Mosty useful for unit testing.
|
||||
*
|
||||
* Should Damnit allow Handlers to force the script to quit?
|
||||
* @param bool $exit
|
||||
*/
|
||||
public function exitWhenDone($exit = true)
|
||||
public function allowQuit($exit = true)
|
||||
{
|
||||
$this->exitWhenDone = (bool) $exit;
|
||||
$this->allowQuit = (bool) $exit;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,15 +153,21 @@ class Run
|
||||
$handlerResponse = $handler->handle($exception);
|
||||
|
||||
if($handlerResponse === Handler::LAST_HANDLER) {
|
||||
// The Handler has handled the exception in some way,
|
||||
// or signals that no further handlers should be queried,
|
||||
// but the script execution will continue
|
||||
break;
|
||||
} elseif($handlerResponse === Handler::QUIT) {
|
||||
// The Handler has handled the exception in some way,
|
||||
// and script execution should terminate, unless specifically
|
||||
// disallowed, in which case the behavior is the same as
|
||||
// Handler::LAST_HANDLER
|
||||
if($this->allowQuit) {
|
||||
exit;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// And we're done!
|
||||
$this->unregister();
|
||||
|
||||
if($this->exitWhenDone) {
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ class RunTest extends TestCase
|
||||
protected function getRunInstance()
|
||||
{
|
||||
$run = new Run;
|
||||
$run->exitWhenDone(false);
|
||||
$run->allowQuit(false);
|
||||
|
||||
return $run;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user