9use InvalidArgumentException;
21 private $allowQuit =
true;
22 private $sendOutput =
true;
27 private $sendHttpCode = 500;
32 private $handlerStack = [];
34 private $silencedPatterns = [];
52 if (is_callable($handler)) {
57 throw new InvalidArgumentException(
58 "Argument to " . __METHOD__ .
" must be a callable, or instance of "
59 .
"Whoops\\Handler\\HandlerInterface"
63 $this->handlerStack[] = $handler;
74 return array_pop($this->handlerStack);
84 return $this->handlerStack;
94 $this->handlerStack = [];
111 public function register()
113 if (!$this->isRegistered) {
116 class_exists(
"\\Whoops\\Exception\\ErrorException");
117 class_exists(
"\\Whoops\\Exception\\FrameCollection");
118 class_exists(
"\\Whoops\\Exception\\Frame");
119 class_exists(
"\\Whoops\\Exception\\Inspector");
121 $this->system->setErrorHandler([$this, self::ERROR_HANDLER]);
122 $this->system->setExceptionHandler([$this, self::EXCEPTION_HANDLER]);
123 $this->system->registerShutdownFunction([$this, self::SHUTDOWN_HANDLER]);
125 $this->isRegistered =
true;
137 if ($this->isRegistered) {
138 $this->system->restoreExceptionHandler();
139 $this->system->restoreErrorHandler();
141 $this->isRegistered =
false;
154 if (func_num_args() == 0) {
155 return $this->allowQuit;
158 return $this->allowQuit = (bool) $exit;
169 $this->silencedPatterns = array_merge(
170 $this->silencedPatterns,
172 function ($pattern) use ($levels) {
174 "pattern" => $pattern,
192 return $this->silencedPatterns;
205 if (func_num_args() == 0) {
206 return $this->sendHttpCode;
210 return $this->sendHttpCode =
false;
213 if (
$code ===
true) {
218 throw new InvalidArgumentException(
219 "Invalid status code '$code', must be 4xx or 5xx"
223 return $this->sendHttpCode =
$code;
234 if (func_num_args() == 0) {
235 return $this->sendOutput;
238 return $this->sendOutput = (bool) $send;
252 $inspector = $this->getInspector($exception);
257 $this->system->startOutputBuffering();
260 $handlerResponse =
null;
261 $handlerContentType =
null;
263 foreach (array_reverse($this->handlerStack) as $handler) {
264 $handler->setRun($this);
265 $handler->setInspector($inspector);
266 $handler->setException($exception);
272 $handlerResponse = $handler->handle($exception);
275 $handlerContentType = method_exists($handler,
'contentType') ? $handler->contentType() :
null;
277 if (in_array($handlerResponse, [Handler::LAST_HANDLER, Handler::QUIT])) {
286 $willQuit = $handlerResponse == Handler::QUIT && $this->allowQuit();
288 $output = $this->system->cleanOutputBuffer();
293 if ($this->writeToOutput()) {
297 while ($this->system->getOutputBufferLevel() > 0) {
298 $this->system->endOutputBuffering();
302 if (Misc::canSendHeaders() && $handlerContentType) {
303 header(
"Content-Type: {$handlerContentType}");
307 $this->writeToOutputNow(
$output);
312 $this->system->flushOutputBuffer();
314 $this->system->stopExecution(1);
336 if ($level & $this->system->getErrorReportingLevel()) {
337 foreach ($this->silencedPatterns as $entry) {
338 $pathMatches = (bool) preg_match($entry[
"pattern"],
$file);
339 $levelMatches = $level & $entry[
"levels"];
340 if ($pathMatches && $levelMatches) {
350 if ($this->canThrowExceptions) {
372 $this->canThrowExceptions =
false;
374 $error = $this->system->getLastError();
391 private $canThrowExceptions =
true;
400 if ($this->sendHttpCode() && \
Whoops\Util\Misc::canSendHeaders()) {
401 $this->system->setHttpResponseCode(
402 $this->sendHttpCode()
An exception for terminatinating execution or to throw for unit testing.
Wraps ErrorException; mostly used for typing (at least now) to easily cleanup the stack trace of redu...
Wrapper for Closures passed as handlers.
Abstract implementation of a Handler.
writeToOutputNow($output)
Echo something to the browser.
writeToOutput($send=null)
Should Whoops push output directly to the client? If this is false, output will be returned by handle...
unregister()
Unregisters all handlers registered by this Whoops\Run instance.
clearHandlers()
Clears all handlers in the handlerStack, including the default PrettyPage handler.
__construct(SystemFacade $system=null)
silenceErrorsInPaths($patterns, $levels=10240)
Silence particular errors in particular files.
allowQuit($exit=null)
Should Whoops allow Handlers to force the script to quit?
handleShutdown()
Special case to deal with Fatal errors and the like.
getHandlers()
Returns an array with all handlers, in the order they were added to the stack.
handleException($exception)
Handles an exception, ultimately generating a Whoops error page.
getSilenceErrorsInPaths()
Returns an array with silent errors in path configuration.
pushHandler($handler)
Pushes a handler to the end of the stack.
handleError($level, $message, $file=null, $line=null)
Converts generic PHP errors to \ErrorException instances, before passing them off to be handled.
popHandler()
Removes the last handler in the stack and returns it.
sendHttpCode($code=null)
Should Whoops send HTTP error code to the browser if possible? Whoops will by default send HTTP code ...
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\s+" &#(? foreach( $entity_files as $file) $output
handleException(CrawlerException $ex)
Whoops - php errors for cool kids.
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file