ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Whoops\Run Class Reference
+ Inheritance diagram for Whoops\Run:
+ Collaboration diagram for Whoops\Run:

Public Member Functions

 __construct (SystemFacade $system=null)
 
 pushHandler ($handler)
 Pushes a handler to the end of the stack. More...
 
 popHandler ()
 Removes the last handler in the stack and returns it. More...
 
 getHandlers ()
 Returns an array with all handlers, in the order they were added to the stack. More...
 
 clearHandlers ()
 Clears all handlers in the handlerStack, including the default PrettyPage handler. More...
 
 register ()
 Registers this instance as an error handler. More...
 
 unregister ()
 Unregisters all handlers registered by this Whoops instance. More...
 
 allowQuit ($exit=null)
 Should Whoops allow Handlers to force the script to quit? More...
 
 silenceErrorsInPaths ($patterns, $levels=10240)
 Silence particular errors in particular files. More...
 
 getSilenceErrorsInPaths ()
 Returns an array with silent errors in path configuration. More...
 
 sendHttpCode ($code=null)
 Should Whoops send HTTP error code to the browser if possible? Whoops will by default send HTTP code 500, but you may wish to use 502, 503, or another 5xx family code. More...
 
 writeToOutput ($send=null)
 Should Whoops push output directly to the client? If this is false, output will be returned by handleException. More...
 
 handleException ($exception)
 Handles an exception, ultimately generating a Whoops error page. More...
 
 handleError ($level, $message, $file=null, $line=null)
 Converts generic PHP errors to instances, before passing them off to be handled. More...
 
 handleShutdown ()
 Special case to deal with Fatal errors and the like. More...
 

Private Member Functions

 getInspector ($exception)
 
 writeToOutputNow ($output)
 Echo something to the browser. More...
 

Private Attributes

 $isRegistered
 
 $allowQuit = true
 
 $sendOutput = true
 
 $sendHttpCode = 500
 
 $handlerStack = []
 
 $silencedPatterns = []
 
 $system
 
 $canThrowExceptions = true
 

Additional Inherited Members

- Data Fields inherited from Whoops\RunInterface
const EXCEPTION_HANDLER = "handleException"
 
const ERROR_HANDLER = "handleError"
 
const SHUTDOWN_HANDLER = "handleShutdown"
 

Detailed Description

Definition at line 18 of file Run.php.

Constructor & Destructor Documentation

◆ __construct()

Whoops\Run::__construct ( SystemFacade  $system = null)

Definition at line 38 of file Run.php.

39  {
40  $this->system = $system ?: new SystemFacade;
41  }
$system
Definition: Run.php:36

Member Function Documentation

◆ allowQuit()

Whoops\Run::allowQuit (   $exit = null)

Should Whoops allow Handlers to force the script to quit?

Parameters
bool | int$exit
Returns
bool

Implements Whoops\RunInterface.

Definition at line 152 of file Run.php.

153  {
154  if (func_num_args() == 0) {
155  return $this->allowQuit;
156  }
157 
158  return $this->allowQuit = (bool) $exit;
159  }
allowQuit($exit=null)
Should Whoops allow Handlers to force the script to quit?
Definition: Run.php:152
$allowQuit
Definition: Run.php:21

◆ clearHandlers()

Whoops\Run::clearHandlers ( )

Clears all handlers in the handlerStack, including the default PrettyPage handler.

Returns
Run

Implements Whoops\RunInterface.

Definition at line 92 of file Run.php.

93  {
94  $this->handlerStack = [];
95  return $this;
96  }

◆ getHandlers()

Whoops\Run::getHandlers ( )

Returns an array with all handlers, in the order they were added to the stack.

Returns
array

Implements Whoops\RunInterface.

Definition at line 82 of file Run.php.

83  {
84  return $this->handlerStack;
85  }
$handlerStack
Definition: Run.php:32

◆ getInspector()

Whoops\Run::getInspector (   $exception)
private
Parameters
\Throwable$exception
Returns
Inspector

Definition at line 102 of file Run.php.

103  {
104  return new Inspector($exception);
105  }

◆ getSilenceErrorsInPaths()

Whoops\Run::getSilenceErrorsInPaths ( )

Returns an array with silent errors in path configuration.

Returns
array

Definition at line 190 of file Run.php.

191  {
193  }
$silencedPatterns
Definition: Run.php:34

◆ handleError()

Whoops\Run::handleError (   $level,
  $message,
  $file = null,
  $line = null 
)

Converts generic PHP errors to instances, before passing them off to be handled.

This method MUST be compatible with set_error_handler.

Parameters
int$level
string$message
string$file
int$line
Returns
bool
Exceptions
ErrorException

Implements Whoops\RunInterface.

Definition at line 334 of file Run.php.

References $file, and $message.

335  {
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) {
341  // Ignore the error, abort handling
342  // See https://github.com/filp/whoops/issues/418
343  return true;
344  }
345  }
346 
347  // XXX we pass $level for the "code" param only for BC reasons.
348  // see https://github.com/filp/whoops/issues/267
349  $exception = new ErrorException($message, /*code*/ $level, /*severity*/ $level, $file, $line);
350  if ($this->canThrowExceptions) {
351  throw $exception;
352  } else {
353  $this->handleException($exception);
354  }
355  // Do not propagate errors which were already handled by Whoops.
356  return true;
357  }
358 
359  // Propagate error to the next handler, allows error_get_last() to
360  // work on silenced errors.
361  return false;
362  }
handleException($exception)
Handles an exception, ultimately generating a Whoops error page.
Definition: Run.php:248
catch(Exception $e) $message
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file

◆ handleException()

Whoops\Run::handleException (   $exception)

Handles an exception, ultimately generating a Whoops error page.

Parameters
\Throwable$exception
Returns
string Output generated by handlers

Implements Whoops\RunInterface.

Definition at line 248 of file Run.php.

References $handler, $output, and header.

249  {
250  // Walk the registered handlers in the reverse order
251  // they were registered, and pass off the exception
252  $inspector = $this->getInspector($exception);
253 
254  // Capture output produced while handling the exception,
255  // we might want to send it straight away to the client,
256  // or return it silently.
257  $this->system->startOutputBuffering();
258 
259  // Just in case there are no handlers:
260  $handlerResponse = null;
261  $handlerContentType = null;
262 
263  foreach (array_reverse($this->handlerStack) as $handler) {
264  $handler->setRun($this);
265  $handler->setInspector($inspector);
266  $handler->setException($exception);
267 
268  // The HandlerInterface does not require an Exception passed to handle()
269  // and neither of our bundled handlers use it.
270  // However, 3rd party handlers may have already relied on this parameter,
271  // and removing it would be possibly breaking for users.
272  $handlerResponse = $handler->handle($exception);
273 
274  // Collect the content type for possible sending in the headers.
275  $handlerContentType = method_exists($handler, 'contentType') ? $handler->contentType() : null;
276 
277  if (in_array($handlerResponse, [Handler::LAST_HANDLER, Handler::QUIT])) {
278  // The Handler has handled the exception in some way, and
279  // wishes to quit execution (Handler::QUIT), or skip any
280  // other handlers (Handler::LAST_HANDLER). If $this->allowQuit
281  // is false, Handler::QUIT behaves like Handler::LAST_HANDLER
282  break;
283  }
284  }
285 
286  $willQuit = $handlerResponse == Handler::QUIT && $this->allowQuit();
287 
288  $output = $this->system->cleanOutputBuffer();
289 
290  // If we're allowed to, send output generated by handlers directly
291  // to the output, otherwise, and if the script doesn't quit, return
292  // it so that it may be used by the caller
293  if ($this->writeToOutput()) {
294  // @todo Might be able to clean this up a bit better
295  if ($willQuit) {
296  // Cleanup all other output buffers before sending our output:
297  while ($this->system->getOutputBufferLevel() > 0) {
298  $this->system->endOutputBuffering();
299  }
300 
301  // Send any headers if needed:
302  if (Misc::canSendHeaders() && $handlerContentType) {
303  header("Content-Type: {$handlerContentType}");
304  }
305  }
306 
307  $this->writeToOutputNow($output);
308  }
309 
310  if ($willQuit) {
311  // HHVM fix for https://github.com/facebook/hhvm/issues/4055
312  $this->system->flushOutputBuffer();
313 
314  $this->system->stopExecution(1);
315  }
316 
317  return $output;
318  }
writeToOutput($send=null)
Should Whoops push output directly to the client? If this is false, output will be returned by handle...
Definition: Run.php:232
getInspector($exception)
Definition: Run.php:102
writeToOutputNow($output)
Echo something to the browser.
Definition: Run.php:398
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
allowQuit($exit=null)
Should Whoops allow Handlers to force the script to quit?
Definition: Run.php:152
Add a drawing to the header
Definition: 04printing.php:69
const QUIT
The Handler has handled the Throwable in some way, and wishes to quit/stop execution.
Definition: Handler.php:31
static canSendHeaders()
Can we at this point in time send HTTP headers?
Definition: Misc.php:21
const LAST_HANDLER
The Handler has handled the Throwable in some way, and wishes to skip any other Handler.
Definition: Handler.php:27
$handler

◆ handleShutdown()

Whoops\Run::handleShutdown ( )

Special case to deal with Fatal errors and the like.

Implements Whoops\RunInterface.

Definition at line 367 of file Run.php.

References $error.

368  {
369  // If we reached this step, we are in shutdown handler.
370  // An exception thrown in a shutdown handler will not be propagated
371  // to the exception handler. Pass that information along.
372  $this->canThrowExceptions = false;
373 
374  $error = $this->system->getLastError();
375  if ($error && Misc::isLevelFatal($error['type'])) {
376  // If there was a fatal error,
377  // it was not handled in handleError yet.
378  $this->handleError(
379  $error['type'],
380  $error['message'],
381  $error['file'],
382  $error['line']
383  );
384  }
385  }
handleError($level, $message, $file=null, $line=null)
Converts generic PHP errors to instances, before passing them off to be handled. ...
Definition: Run.php:334
$error
Definition: Error.php:17
static isLevelFatal($level)
Determine if an error level is fatal (halts execution)
Definition: Misc.php:67

◆ popHandler()

Whoops\Run::popHandler ( )

Removes the last handler in the stack and returns it.

Returns null if there"s nothing else to pop.

Returns
null|HandlerInterface

Implements Whoops\RunInterface.

Definition at line 72 of file Run.php.

73  {
74  return array_pop($this->handlerStack);
75  }

◆ pushHandler()

Whoops\Run::pushHandler (   $handler)

Pushes a handler to the end of the stack.

Exceptions
InvalidArgumentExceptionIf argument is not callable or instance of HandlerInterface
Parameters
Callable | HandlerInterface$handler
Returns
Run

Implements Whoops\RunInterface.

Definition at line 50 of file Run.php.

References $handler.

51  {
52  if (is_callable($handler)) {
53  $handler = new CallbackHandler($handler);
54  }
55 
56  if (!$handler instanceof HandlerInterface) {
57  throw new InvalidArgumentException(
58  "Argument to " . __METHOD__ . " must be a callable, or instance of "
59  . "Whoops\\Handler\\HandlerInterface"
60  );
61  }
62 
63  $this->handlerStack[] = $handler;
64  return $this;
65  }
$handler

◆ register()

Whoops\Run::register ( )

Registers this instance as an error handler.

Returns
Run

Implements Whoops\RunInterface.

Definition at line 111 of file Run.php.

112  {
113  if (!$this->isRegistered) {
114  // Workaround PHP bug 42098
115  // https://bugs.php.net/bug.php?id=42098
116  class_exists("\\Whoops\\Exception\\ErrorException");
117  class_exists("\\Whoops\\Exception\\FrameCollection");
118  class_exists("\\Whoops\\Exception\\Frame");
119  class_exists("\\Whoops\\Exception\\Inspector");
120 
121  $this->system->setErrorHandler([$this, self::ERROR_HANDLER]);
122  $this->system->setExceptionHandler([$this, self::EXCEPTION_HANDLER]);
123  $this->system->registerShutdownFunction([$this, self::SHUTDOWN_HANDLER]);
124 
125  $this->isRegistered = true;
126  }
127 
128  return $this;
129  }

◆ sendHttpCode()

Whoops\Run::sendHttpCode (   $code = null)

Should Whoops send HTTP error code to the browser if possible? Whoops will by default send HTTP code 500, but you may wish to use 502, 503, or another 5xx family code.

Parameters
bool | int$code
Returns
int|false

Implements Whoops\RunInterface.

Definition at line 203 of file Run.php.

References $code.

204  {
205  if (func_num_args() == 0) {
206  return $this->sendHttpCode;
207  }
208 
209  if (!$code) {
210  return $this->sendHttpCode = false;
211  }
212 
213  if ($code === true) {
214  $code = 500;
215  }
216 
217  if ($code < 400 || 600 <= $code) {
218  throw new InvalidArgumentException(
219  "Invalid status code '$code', must be 4xx or 5xx"
220  );
221  }
222 
223  return $this->sendHttpCode = $code;
224  }
$code
Definition: example_050.php:99
sendHttpCode($code=null)
Should Whoops send HTTP error code to the browser if possible? Whoops will by default send HTTP code ...
Definition: Run.php:203
$sendHttpCode
Definition: Run.php:27

◆ silenceErrorsInPaths()

Whoops\Run::silenceErrorsInPaths (   $patterns,
  $levels = 10240 
)

Silence particular errors in particular files.

Parameters
array | string$patternsList or a single regex pattern to match
int$levelsDefaults to E_STRICT | E_DEPRECATED
Returns

Implements Whoops\RunInterface.

Definition at line 167 of file Run.php.

References array.

168  {
169  $this->silencedPatterns = array_merge(
170  $this->silencedPatterns,
171  array_map(
172  function ($pattern) use ($levels) {
173  return [
174  "pattern" => $pattern,
175  "levels" => $levels,
176  ];
177  },
178  (array) $patterns
179  )
180  );
181  return $this;
182  }
Create styles array
The data for the language used.

◆ unregister()

Whoops\Run::unregister ( )

Unregisters all handlers registered by this Whoops instance.

Returns
Run

Implements Whoops\RunInterface.

Definition at line 135 of file Run.php.

136  {
137  if ($this->isRegistered) {
138  $this->system->restoreExceptionHandler();
139  $this->system->restoreErrorHandler();
140 
141  $this->isRegistered = false;
142  }
143 
144  return $this;
145  }

◆ writeToOutput()

Whoops\Run::writeToOutput (   $send = null)

Should Whoops push output directly to the client? If this is false, output will be returned by handleException.

Parameters
bool | int$send
Returns
bool

Implements Whoops\RunInterface.

Definition at line 232 of file Run.php.

233  {
234  if (func_num_args() == 0) {
235  return $this->sendOutput;
236  }
237 
238  return $this->sendOutput = (bool) $send;
239  }
$sendOutput
Definition: Run.php:22

◆ writeToOutputNow()

Whoops\Run::writeToOutputNow (   $output)
private

Echo something to the browser.

Parameters
string$output
Returns
$this

Definition at line 398 of file Run.php.

References $output.

399  {
400  if ($this->sendHttpCode() && \Whoops\Util\Misc::canSendHeaders()) {
401  $this->system->setHttpResponseCode(
402  $this->sendHttpCode()
403  );
404  }
405 
406  echo $output;
407 
408  return $this;
409  }
sendHttpCode($code=null)
Should Whoops send HTTP error code to the browser if possible? Whoops will by default send HTTP code ...
Definition: Run.php:203
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
Whoops - php errors for cool kids.
static canSendHeaders()
Can we at this point in time send HTTP headers?
Definition: Misc.php:21

Field Documentation

◆ $allowQuit

Whoops\Run::$allowQuit = true
private

Definition at line 21 of file Run.php.

◆ $canThrowExceptions

Whoops\Run::$canThrowExceptions = true
private

Definition at line 391 of file Run.php.

◆ $handlerStack

Whoops\Run::$handlerStack = []
private

Definition at line 32 of file Run.php.

◆ $isRegistered

Whoops\Run::$isRegistered
private

Definition at line 20 of file Run.php.

◆ $sendHttpCode

Whoops\Run::$sendHttpCode = 500
private

Definition at line 27 of file Run.php.

◆ $sendOutput

Whoops\Run::$sendOutput = true
private

Definition at line 22 of file Run.php.

◆ $silencedPatterns

Whoops\Run::$silencedPatterns = []
private

Definition at line 34 of file Run.php.

◆ $system

Whoops\Run::$system
private

Definition at line 36 of file Run.php.


The documentation for this class was generated from the following file: