MockExceptionHandler
extends ExceptionHandler
in package
ExceptionHandler converts an exception to a Response object.
It is mostly useful in debug mode to replace the default PHP/XDebug output with something prettier and more useful.
As this class is mainly used during Kernel boot, where nothing is yet available, the Response content is always HTML.
Table of Contents
Properties
- $e : mixed
- $caughtBuffer : mixed
- $caughtLength : mixed
- $charset : mixed
- $debug : mixed
- $fileLinkFormat : mixed
- $handler : mixed
Methods
- __construct() : mixed
- getContent() : string
- Gets the HTML content associated with the given exception.
- getHtml() : string
- Gets the full HTML content associated with the given exception.
- getStylesheet() : string
- Gets the stylesheet associated with the given exception.
- handle() : mixed
- Sends a response for the given Exception.
- register() : static
- Registers the exception handler.
- sendPhpResponse() : mixed
- Sends the error associated with the given Exception as a plain PHP response.
- setFileLinkFormat() : string
- Sets the format for links to source files.
- setHandler() : callable|null
- Sets a user exception handler.
- decorate() : mixed
- escapeHtml() : mixed
- HTML-encodes a string.
- formatArgs() : string
- Formats an array as a string.
- formatClass() : mixed
- formatPath() : mixed
- getSymfonyGhostAsSvg() : mixed
Properties
$e
public
mixed
$e
$caughtBuffer
private
mixed
$caughtBuffer
$caughtLength
private
mixed
$caughtLength
$charset
private
mixed
$charset
$debug
private
mixed
$debug
$fileLinkFormat
private
mixed
$fileLinkFormat
$handler
private
mixed
$handler
Methods
__construct()
public
__construct([mixed $debug = true ][, mixed $charset = null ][, mixed $fileLinkFormat = null ]) : mixed
Parameters
- $debug : mixed = true
- $charset : mixed = null
- $fileLinkFormat : mixed = null
getContent()
Gets the HTML content associated with the given exception.
public
getContent(FlattenException $exception) : string
Parameters
- $exception : FlattenException
-
A FlattenException instance
Return values
string —The content as a string
getHtml()
Gets the full HTML content associated with the given exception.
public
getHtml(Exception|FlattenException $exception) : string
Parameters
- $exception : Exception|FlattenException
-
An \Exception or FlattenException instance
Return values
string —The HTML content as a string
getStylesheet()
Gets the stylesheet associated with the given exception.
public
getStylesheet(FlattenException $exception) : string
Parameters
- $exception : FlattenException
-
A FlattenException instance
Return values
string —The stylesheet as a string
handle()
Sends a response for the given Exception.
public
handle(Exception $e) : mixed
To be as fail-safe as possible, the exception is first handled by our simple exception handler, then by the user exception handler. The latter takes precedence and any output from the former is cancelled, if and only if nothing bad happens in this handling path.
Parameters
- $e : Exception
register()
Registers the exception handler.
public
static register([bool $debug = true ][, string|null $charset = null ][, string|null $fileLinkFormat = null ]) : static
Parameters
- $debug : bool = true
-
Enable/disable debug mode, where the stack trace is displayed
- $charset : string|null = null
-
The charset used by exception messages
- $fileLinkFormat : string|null = null
-
The IDE link template
Return values
staticsendPhpResponse()
Sends the error associated with the given Exception as a plain PHP response.
public
sendPhpResponse(Exception|FlattenException $exception) : mixed
This method uses plain PHP functions like header() and echo to output the response.
Parameters
- $exception : Exception|FlattenException
-
An \Exception or FlattenException instance
setFileLinkFormat()
Sets the format for links to source files.
public
setFileLinkFormat(string|FileLinkFormatter $fileLinkFormat) : string
Parameters
- $fileLinkFormat : string|FileLinkFormatter
-
The format for links to source files
Return values
string —The previous file link format
setHandler()
Sets a user exception handler.
public
setHandler([callable $handler = null ]) : callable|null
Parameters
- $handler : callable = null
-
An handler that will be called on Exception
Return values
callable|null —The previous exception handler if any
decorate()
private
decorate(mixed $content, mixed $css) : mixed
Parameters
- $content : mixed
- $css : mixed
escapeHtml()
HTML-encodes a string.
private
escapeHtml(mixed $str) : mixed
Parameters
- $str : mixed
formatArgs()
Formats an array as a string.
private
formatArgs(array<string|int, mixed> $args) : string
Parameters
- $args : array<string|int, mixed>
-
The argument array
Return values
stringformatClass()
private
formatClass(mixed $class) : mixed
Parameters
- $class : mixed
formatPath()
private
formatPath(mixed $path, mixed $line) : mixed
Parameters
- $path : mixed
- $line : mixed
getSymfonyGhostAsSvg()
private
getSymfonyGhostAsSvg() : mixed