code
stringlengths 31
1.39M
| docstring
stringlengths 23
16.8k
| func_name
stringlengths 1
126
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
166
| url
stringlengths 50
220
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
public function prependFrames(array $frames)
{
$this->frames = array_merge($frames, $this->frames);
}
|
@param Frame[] $frames Array of Frame instances, usually from $e->getPrevious()
|
prependFrames
|
php
|
filp/whoops
|
src/Whoops/Exception/FrameCollection.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Exception/FrameCollection.php
|
MIT
|
public function topDiff(FrameCollection $parentFrames)
{
$diff = $this->frames;
$parentFrames = $parentFrames->getArray();
$p = count($parentFrames)-1;
for ($i = count($diff)-1; $i >= 0 && $p >= 0; $i--) {
/** @var Frame $tailFrame */
$tailFrame = $diff[$i];
if ($tailFrame->equals($parentFrames[$p])) {
unset($diff[$i]);
}
$p--;
}
return $diff;
}
|
Gets the innermost part of stack trace that is not the same as that of outer exception
@param FrameCollection $parentFrames Outer exception frames to compare tail against
@return Frame[]
|
topDiff
|
php
|
filp/whoops
|
src/Whoops/Exception/FrameCollection.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Exception/FrameCollection.php
|
MIT
|
public function __construct($exception, $factory = null)
{
$this->exception = $exception;
$this->inspectorFactory = $factory ?: new InspectorFactory();
}
|
@param \Throwable $exception The exception to inspect
@param \Whoops\Inspector\InspectorFactoryInterface $factory
|
__construct
|
php
|
filp/whoops
|
src/Whoops/Exception/Inspector.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Exception/Inspector.php
|
MIT
|
public function getExceptionDocrefUrl()
{
return $this->extractDocrefUrl($this->exception->getMessage())['url'];
}
|
Returns a url to the php-manual related to the underlying error - when available.
@return string|null
|
getExceptionDocrefUrl
|
php
|
filp/whoops
|
src/Whoops/Exception/Inspector.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Exception/Inspector.php
|
MIT
|
public function hasPreviousException()
{
return $this->previousExceptionInspector || $this->exception->getPrevious();
}
|
Does the wrapped Exception has a previous Exception?
@return bool
|
hasPreviousException
|
php
|
filp/whoops
|
src/Whoops/Exception/Inspector.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Exception/Inspector.php
|
MIT
|
public function getPreviousExceptionInspector()
{
if ($this->previousExceptionInspector === null) {
$previousException = $this->exception->getPrevious();
if ($previousException) {
$this->previousExceptionInspector = $this->inspectorFactory->create($previousException);
}
}
return $this->previousExceptionInspector;
}
|
Returns an Inspector for a previous Exception, if any.
@todo Clean this up a bit, cache stuff a bit better.
@return Inspector
|
getPreviousExceptionInspector
|
php
|
filp/whoops
|
src/Whoops/Exception/Inspector.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Exception/Inspector.php
|
MIT
|
public function getPreviousExceptions()
{
if ($this->previousExceptions === null) {
$this->previousExceptions = [];
$prev = $this->exception->getPrevious();
while ($prev !== null) {
$this->previousExceptions[] = $prev;
$prev = $prev->getPrevious();
}
}
return $this->previousExceptions;
}
|
Returns an array of all previous exceptions for this inspector's exception
@return \Throwable[]
|
getPreviousExceptions
|
php
|
filp/whoops
|
src/Whoops/Exception/Inspector.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Exception/Inspector.php
|
MIT
|
public function getFrames(array $frameFilters = [])
{
if ($this->frames === null) {
$frames = $this->getTrace($this->exception);
// Fill empty line/file info for call_user_func_array usages (PHP Bug #44428)
foreach ($frames as $k => $frame) {
if (empty($frame['file'])) {
// Default values when file and line are missing
$file = '[internal]';
$line = 0;
$next_frame = !empty($frames[$k + 1]) ? $frames[$k + 1] : [];
if ($this->isValidNextFrame($next_frame)) {
$file = $next_frame['file'];
$line = $next_frame['line'];
}
$frames[$k]['file'] = $file;
$frames[$k]['line'] = $line;
}
}
// Find latest non-error handling frame index ($i) used to remove error handling frames
$i = 0;
foreach ($frames as $k => $frame) {
if ($frame['file'] == $this->exception->getFile() && $frame['line'] == $this->exception->getLine()) {
$i = $k;
}
}
// Remove error handling frames
if ($i > 0) {
array_splice($frames, 0, $i);
}
$firstFrame = $this->getFrameFromException($this->exception);
array_unshift($frames, $firstFrame);
$this->frames = new FrameCollection($frames);
if ($previousInspector = $this->getPreviousExceptionInspector()) {
// Keep outer frame on top of the inner one
$outerFrames = $this->frames;
$newFrames = clone $previousInspector->getFrames();
// I assume it will always be set, but let's be safe
if (isset($newFrames[0])) {
$newFrames[0]->addComment(
$previousInspector->getExceptionMessage(),
'Exception message:'
);
}
$newFrames->prependFrames($outerFrames->topDiff($newFrames));
$this->frames = $newFrames;
}
// Apply frame filters callbacks on the frames stack
if (!empty($frameFilters)) {
foreach ($frameFilters as $filterCallback) {
$this->frames->filter($filterCallback);
}
}
}
return $this->frames;
}
|
Returns an iterator for the inspected exception's
frames.
@param array<callable> $frameFilters
@return \Whoops\Exception\FrameCollection
|
getFrames
|
php
|
filp/whoops
|
src/Whoops/Exception/Inspector.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Exception/Inspector.php
|
MIT
|
protected function getTrace($e)
{
$traces = $e->getTrace();
// Get trace from xdebug if enabled, failure exceptions only trace to the shutdown handler by default
if (!$e instanceof \ErrorException) {
return $traces;
}
if (!Misc::isLevelFatal($e->getSeverity())) {
return $traces;
}
if (!extension_loaded('xdebug') || !function_exists('xdebug_is_enabled') || !xdebug_is_enabled()) {
return $traces;
}
// Use xdebug to get the full stack trace and remove the shutdown handler stack trace
$stack = array_reverse(xdebug_get_function_stack());
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$traces = array_diff_key($stack, $trace);
return $traces;
}
|
Gets the backtrace from an exception.
If xdebug is installed
@param \Throwable $e
@return array
|
getTrace
|
php
|
filp/whoops
|
src/Whoops/Exception/Inspector.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Exception/Inspector.php
|
MIT
|
protected function getFrameFromException($exception)
{
return [
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'class' => get_class($exception),
'args' => [
$exception->getMessage(),
],
];
}
|
Given an exception, generates an array in the format
generated by Exception::getTrace()
@param \Throwable $exception
@return array
|
getFrameFromException
|
php
|
filp/whoops
|
src/Whoops/Exception/Inspector.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Exception/Inspector.php
|
MIT
|
protected function getFrameFromError(ErrorException $exception)
{
return [
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'class' => null,
'args' => [],
];
}
|
Given an error, generates an array in the format
generated by ErrorException
@param ErrorException $exception
@return array
|
getFrameFromError
|
php
|
filp/whoops
|
src/Whoops/Exception/Inspector.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Exception/Inspector.php
|
MIT
|
protected function isValidNextFrame(array $frame)
{
if (empty($frame['file'])) {
return false;
}
if (empty($frame['line'])) {
return false;
}
if (empty($frame['function']) || !stristr($frame['function'], 'call_user_func')) {
return false;
}
return true;
}
|
Determine if the frame can be used to fill in previous frame's missing info
happens for call_user_func and call_user_func_array usages (PHP Bug #44428)
@return bool
|
isValidNextFrame
|
php
|
filp/whoops
|
src/Whoops/Exception/Inspector.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Exception/Inspector.php
|
MIT
|
public function __construct($callable)
{
if (!is_callable($callable)) {
throw new InvalidArgumentException(
'Argument to ' . __METHOD__ . ' must be valid callable'
);
}
$this->callable = $callable;
}
|
@throws InvalidArgumentException If argument is not callable
@param callable $callable
|
__construct
|
php
|
filp/whoops
|
src/Whoops/Handler/CallbackHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/CallbackHandler.php
|
MIT
|
public function setJsonApi($jsonApi = false)
{
$this->jsonApi = (bool) $jsonApi;
return $this;
}
|
Returns errors[[]] instead of error[] to be in compliance with the json:api spec
@param bool $jsonApi Default is false
@return static
|
setJsonApi
|
php
|
filp/whoops
|
src/Whoops/Handler/JsonResponseHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/JsonResponseHandler.php
|
MIT
|
public function addTraceToOutput($returnFrames = null)
{
if (func_num_args() == 0) {
return $this->returnFrames;
}
$this->returnFrames = (bool) $returnFrames;
return $this;
}
|
@param bool|null $returnFrames
@return bool|static
|
addTraceToOutput
|
php
|
filp/whoops
|
src/Whoops/Handler/JsonResponseHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/JsonResponseHandler.php
|
MIT
|
public function __construct($logger = null)
{
$this->setLogger($logger);
}
|
Constructor.
@throws InvalidArgumentException If argument is not null or a LoggerInterface
@param \Psr\Log\LoggerInterface|null $logger
|
__construct
|
php
|
filp/whoops
|
src/Whoops/Handler/PlainTextHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PlainTextHandler.php
|
MIT
|
public function setLogger($logger = null)
{
if (! (is_null($logger)
|| $logger instanceof LoggerInterface)) {
throw new InvalidArgumentException(
'Argument to ' . __METHOD__ .
" must be a valid Logger Interface (aka. Monolog), " .
get_class($logger) . ' given.'
);
}
$this->logger = $logger;
}
|
Set the output logger interface.
@throws InvalidArgumentException If argument is not null or a LoggerInterface
@param \Psr\Log\LoggerInterface|null $logger
|
setLogger
|
php
|
filp/whoops
|
src/Whoops/Handler/PlainTextHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PlainTextHandler.php
|
MIT
|
public function setDumper(callable $dumper)
{
$this->dumper = $dumper;
return $this;
}
|
Set var dumper callback function.
@param callable $dumper
@return static
|
setDumper
|
php
|
filp/whoops
|
src/Whoops/Handler/PlainTextHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PlainTextHandler.php
|
MIT
|
public function addTraceToOutput($addTraceToOutput = null)
{
if (func_num_args() == 0) {
return $this->addTraceToOutput;
}
$this->addTraceToOutput = (bool) $addTraceToOutput;
return $this;
}
|
Add error trace to output.
@param bool|null $addTraceToOutput
@return bool|static
|
addTraceToOutput
|
php
|
filp/whoops
|
src/Whoops/Handler/PlainTextHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PlainTextHandler.php
|
MIT
|
public function addPreviousToOutput($addPreviousToOutput = null)
{
if (func_num_args() == 0) {
return $this->addPreviousToOutput;
}
$this->addPreviousToOutput = (bool) $addPreviousToOutput;
return $this;
}
|
Add previous exceptions to output.
@param bool|null $addPreviousToOutput
@return bool|static
|
addPreviousToOutput
|
php
|
filp/whoops
|
src/Whoops/Handler/PlainTextHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PlainTextHandler.php
|
MIT
|
public function addTraceFunctionArgsToOutput($addTraceFunctionArgsToOutput = null)
{
if (func_num_args() == 0) {
return $this->addTraceFunctionArgsToOutput;
}
if (! is_integer($addTraceFunctionArgsToOutput)) {
$this->addTraceFunctionArgsToOutput = (bool) $addTraceFunctionArgsToOutput;
} else {
$this->addTraceFunctionArgsToOutput = $addTraceFunctionArgsToOutput;
}
return $this;
}
|
Add error trace function arguments to output.
Set to True for all frame args, or integer for the n first frame args.
@param bool|integer|null $addTraceFunctionArgsToOutput
@return static|bool|integer
|
addTraceFunctionArgsToOutput
|
php
|
filp/whoops
|
src/Whoops/Handler/PlainTextHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PlainTextHandler.php
|
MIT
|
public function generateResponse()
{
$exception = $this->getException();
$message = $this->getExceptionOutput($exception);
if ($this->addPreviousToOutput) {
$previous = $exception->getPrevious();
while ($previous) {
$message .= "\n\nCaused by\n" . $this->getExceptionOutput($previous);
$previous = $previous->getPrevious();
}
}
return $message . $this->getTraceOutput() . "\n";
}
|
Create plain text response and return it as a string
@return string
|
generateResponse
|
php
|
filp/whoops
|
src/Whoops/Handler/PlainTextHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PlainTextHandler.php
|
MIT
|
public function loggerOnly($loggerOnly = null)
{
if (func_num_args() == 0) {
return $this->loggerOnly;
}
$this->loggerOnly = (bool) $loggerOnly;
return $this;
}
|
Only output to logger.
@param bool|null $loggerOnly
@return static|bool
|
loggerOnly
|
php
|
filp/whoops
|
src/Whoops/Handler/PlainTextHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PlainTextHandler.php
|
MIT
|
private function canOutput()
{
return !$this->loggerOnly();
}
|
Test if handler can output to stdout.
@return bool
|
canOutput
|
php
|
filp/whoops
|
src/Whoops/Handler/PlainTextHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PlainTextHandler.php
|
MIT
|
private function getFrameArgsOutput(Frame $frame, $line)
{
if ($this->addTraceFunctionArgsToOutput() === false
|| $this->addTraceFunctionArgsToOutput() < $line) {
return '';
}
// Dump the arguments:
ob_start();
$this->dump($frame->getArgs());
if (ob_get_length() > $this->getTraceFunctionArgsOutputLimit()) {
// The argument var_dump is to big.
// Discarded to limit memory usage.
ob_clean();
return sprintf(
"\n%sArguments dump length greater than %d Bytes. Discarded.",
self::VAR_DUMP_PREFIX,
$this->getTraceFunctionArgsOutputLimit()
);
}
return sprintf(
"\n%s",
preg_replace('/^/m', self::VAR_DUMP_PREFIX, ob_get_clean())
);
}
|
Get the frame args var_dump.
@param \Whoops\Exception\Frame $frame [description]
@param integer $line [description]
@return string
|
getFrameArgsOutput
|
php
|
filp/whoops
|
src/Whoops/Handler/PlainTextHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PlainTextHandler.php
|
MIT
|
protected function dump($var)
{
if ($this->dumper) {
call_user_func($this->dumper, $var);
} else {
var_dump($var);
}
}
|
Dump variable.
@param mixed $var
@return void
|
dump
|
php
|
filp/whoops
|
src/Whoops/Handler/PlainTextHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PlainTextHandler.php
|
MIT
|
private function getTraceOutput()
{
if (! $this->addTraceToOutput()) {
return '';
}
$inspector = $this->getInspector();
$frames = $inspector->getFrames($this->getRun()->getFrameFilters());
$response = "\nStack trace:";
$line = 1;
foreach ($frames as $frame) {
/** @var Frame $frame */
$class = $frame->getClass();
$template = "\n%3d. %s->%s() %s:%d%s";
if (! $class) {
// Remove method arrow (->) from output.
$template = "\n%3d. %s%s() %s:%d%s";
}
$response .= sprintf(
$template,
$line,
$class,
$frame->getFunction(),
$frame->getFile(),
$frame->getLine(),
$this->getFrameArgsOutput($frame, $line)
);
$line++;
}
return $response;
}
|
Get the exception trace as plain text.
@return string
|
getTraceOutput
|
php
|
filp/whoops
|
src/Whoops/Handler/PlainTextHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PlainTextHandler.php
|
MIT
|
private function getExceptionOutput($exception)
{
return sprintf(
"%s: %s in file %s on line %d",
get_class($exception),
$exception->getMessage(),
$exception->getFile(),
$exception->getLine()
);
}
|
Get the exception as plain text.
@param \Throwable $exception
@return string
|
getExceptionOutput
|
php
|
filp/whoops
|
src/Whoops/Handler/PlainTextHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PlainTextHandler.php
|
MIT
|
protected function getExceptionFrames()
{
$frames = $this->getInspector()->getFrames($this->getRun()->getFrameFilters());
if ($this->getApplicationPaths()) {
foreach ($frames as $frame) {
foreach ($this->getApplicationPaths() as $path) {
if (strpos($frame->getFile(), $path) === 0) {
$frame->setApplication(true);
break;
}
}
}
}
return $frames;
}
|
Get the stack trace frames of the exception currently being handled.
@return \Whoops\Exception\FrameCollection
|
getExceptionFrames
|
php
|
filp/whoops
|
src/Whoops/Handler/PrettyPageHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PrettyPageHandler.php
|
MIT
|
protected function getExceptionCode()
{
$exception = $this->getException();
$code = $exception->getCode();
if ($exception instanceof \ErrorException) {
// ErrorExceptions wrap the php-error types within the 'severity' property
$code = Misc::translateErrorCode($exception->getSeverity());
}
return (string) $code;
}
|
Get the code of the exception currently being handled.
@return string
|
getExceptionCode
|
php
|
filp/whoops
|
src/Whoops/Handler/PrettyPageHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PrettyPageHandler.php
|
MIT
|
public function addDataTable($label, array $data)
{
$this->extraTables[$label] = $data;
return $this;
}
|
Adds an entry to the list of tables displayed in the template.
The expected data is a simple associative array. Any nested arrays
will be flattened with `print_r`.
@param string $label
@return static
|
addDataTable
|
php
|
filp/whoops
|
src/Whoops/Handler/PrettyPageHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PrettyPageHandler.php
|
MIT
|
public function addDataTableCallback($label, /* callable */ $callback)
{
if (!is_callable($callback)) {
throw new InvalidArgumentException('Expecting callback argument to be callable');
}
$this->extraTables[$label] = function (?\Whoops\Inspector\InspectorInterface $inspector = null) use ($callback) {
try {
$result = call_user_func($callback, $inspector);
// Only return the result if it can be iterated over by foreach().
return is_array($result) || $result instanceof \Traversable ? $result : [];
} catch (\Exception $e) {
// Don't allow failure to break the rendering of the original exception.
return [];
}
};
return $this;
}
|
Lazily adds an entry to the list of tables displayed in the table.
The supplied callback argument will be called when the error is
rendered, it should produce a simple associative array. Any nested
arrays will be flattened with `print_r`.
@param string $label
@param callable $callback Callable returning an associative array
@throws InvalidArgumentException If $callback is not callable
@return static
|
addDataTableCallback
|
php
|
filp/whoops
|
src/Whoops/Handler/PrettyPageHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PrettyPageHandler.php
|
MIT
|
public function getDataTables($label = null)
{
if ($label !== null) {
return isset($this->extraTables[$label]) ?
$this->extraTables[$label] : [];
}
return $this->extraTables;
}
|
Returns all the extra data tables registered with this handler.
Optionally accepts a 'label' parameter, to only return the data table
under that label.
@param string|null $label
@return array[]|callable
|
getDataTables
|
php
|
filp/whoops
|
src/Whoops/Handler/PrettyPageHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PrettyPageHandler.php
|
MIT
|
public function handleUnconditionally($value = null)
{
if (func_num_args() == 0) {
return $this->handleUnconditionally;
}
$this->handleUnconditionally = (bool) $value;
return $this;
}
|
Set whether to handle unconditionally.
Allows to disable all attempts to dynamically decide whether to handle
or return prematurely. Set this to ensure that the handler will perform,
no matter what.
@param bool|null $value
@return bool|static
|
handleUnconditionally
|
php
|
filp/whoops
|
src/Whoops/Handler/PrettyPageHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PrettyPageHandler.php
|
MIT
|
public function addEditor($identifier, $resolver)
{
$this->editors[$identifier] = $resolver;
return $this;
}
|
Adds an editor resolver.
Either a string, or a closure that resolves a string, that can be used
to open a given file in an editor. If the string contains the special
substrings %file or %line, they will be replaced with the correct data.
@example
$run->addEditor('macvim', "mvim://open?url=file://%file&line=%line")
@example
$run->addEditor('remove-it', function($file, $line) {
unlink($file);
return "http://stackoverflow.com";
});
@param string $identifier
@param string|callable $resolver
@return static
|
addEditor
|
php
|
filp/whoops
|
src/Whoops/Handler/PrettyPageHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PrettyPageHandler.php
|
MIT
|
public function setEditor($editor)
{
if (!is_callable($editor) && !isset($this->editors[$editor])) {
throw new InvalidArgumentException(
"Unknown editor identifier: $editor. Known editors:" .
implode(",", array_keys($this->editors))
);
}
$this->editor = $editor;
return $this;
}
|
Set the editor to use to open referenced files.
Pass either the name of a configured editor, or a closure that directly
resolves an editor string.
@example
$run->setEditor(function($file, $line) { return "file:///{$file}"; });
@example
$run->setEditor('sublime');
@param string|callable $editor
@throws InvalidArgumentException If invalid argument identifier provided
@return static
|
setEditor
|
php
|
filp/whoops
|
src/Whoops/Handler/PrettyPageHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PrettyPageHandler.php
|
MIT
|
public function getEditorHref($filePath, $line)
{
$editor = $this->getEditor($filePath, $line);
if (empty($editor)) {
return false;
}
// Check that the editor is a string, and replace the
// %line and %file placeholders:
if (!isset($editor['url']) || !is_string($editor['url'])) {
throw new UnexpectedValueException(
__METHOD__ . " should always resolve to a string or a valid editor array; got something else instead."
);
}
$editor['url'] = str_replace("%line", rawurlencode($line), $editor['url']);
$editor['url'] = str_replace("%file", rawurlencode($filePath), $editor['url']);
return $editor['url'];
}
|
Get the editor href for a given file and line, if available.
@param string $filePath
@param int $line
@throws InvalidArgumentException If editor resolver does not return a string
@return string|bool
|
getEditorHref
|
php
|
filp/whoops
|
src/Whoops/Handler/PrettyPageHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PrettyPageHandler.php
|
MIT
|
public function getEditorAjax($filePath, $line)
{
$editor = $this->getEditor($filePath, $line);
// Check that the ajax is a bool
if (!isset($editor['ajax']) || !is_bool($editor['ajax'])) {
throw new UnexpectedValueException(
__METHOD__ . " should always resolve to a bool; got something else instead."
);
}
return $editor['ajax'];
}
|
Determine if the editor link should act as an Ajax request.
@param string $filePath
@param int $line
@throws UnexpectedValueException If editor resolver does not return a boolean
@return bool
|
getEditorAjax
|
php
|
filp/whoops
|
src/Whoops/Handler/PrettyPageHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PrettyPageHandler.php
|
MIT
|
protected function getEditor($filePath, $line)
{
if (!$this->editor || (!is_string($this->editor) && !is_callable($this->editor))) {
return [];
}
if (is_string($this->editor) && isset($this->editors[$this->editor]) && !is_callable($this->editors[$this->editor])) {
return [
'ajax' => false,
'url' => $this->editors[$this->editor],
];
}
if (is_callable($this->editor) || (isset($this->editors[$this->editor]) && is_callable($this->editors[$this->editor]))) {
if (is_callable($this->editor)) {
$callback = call_user_func($this->editor, $filePath, $line);
} else {
$callback = call_user_func($this->editors[$this->editor], $filePath, $line);
}
if (empty($callback)) {
return [];
}
if (is_string($callback)) {
return [
'ajax' => false,
'url' => $callback,
];
}
return [
'ajax' => isset($callback['ajax']) ? $callback['ajax'] : false,
'url' => isset($callback['url']) ? $callback['url'] : $callback,
];
}
return [];
}
|
Determines both the editor and if ajax should be used.
@param string $filePath
@param int $line
@return array
|
getEditor
|
php
|
filp/whoops
|
src/Whoops/Handler/PrettyPageHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PrettyPageHandler.php
|
MIT
|
public function setPageTitle($title)
{
$this->pageTitle = (string) $title;
return $this;
}
|
Set the page title.
@param string $title
@return static
|
setPageTitle
|
php
|
filp/whoops
|
src/Whoops/Handler/PrettyPageHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PrettyPageHandler.php
|
MIT
|
public function getPageTitle()
{
return $this->pageTitle;
}
|
Get the page title.
@return string
|
getPageTitle
|
php
|
filp/whoops
|
src/Whoops/Handler/PrettyPageHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PrettyPageHandler.php
|
MIT
|
public function addResourcePath($path)
{
if (!is_dir($path)) {
throw new InvalidArgumentException(
"'$path' is not a valid directory"
);
}
array_unshift($this->searchPaths, $path);
return $this;
}
|
Adds a path to the list of paths to be searched for resources.
@param string $path
@throws InvalidArgumentException If $path is not a valid directory
@return static
|
addResourcePath
|
php
|
filp/whoops
|
src/Whoops/Handler/PrettyPageHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PrettyPageHandler.php
|
MIT
|
public function addCustomCss($name)
{
$this->customCss = $name;
return $this;
}
|
Adds a custom css file to be loaded.
@param string|null $name
@return static
|
addCustomCss
|
php
|
filp/whoops
|
src/Whoops/Handler/PrettyPageHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PrettyPageHandler.php
|
MIT
|
public function addCustomJs($name)
{
$this->customJs = $name;
return $this;
}
|
Adds a custom js file to be loaded.
@param string|null $name
@return static
|
addCustomJs
|
php
|
filp/whoops
|
src/Whoops/Handler/PrettyPageHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PrettyPageHandler.php
|
MIT
|
protected function getResource($resource)
{
// If the resource was found before, we can speed things up
// by caching its absolute, resolved path:
if (isset($this->resourceCache[$resource])) {
return $this->resourceCache[$resource];
}
// Search through available search paths, until we find the
// resource we're after:
foreach ($this->searchPaths as $path) {
$fullPath = $path . "/$resource";
if (is_file($fullPath)) {
// Cache the result:
$this->resourceCache[$resource] = $fullPath;
return $fullPath;
}
}
// If we got this far, nothing was found.
throw new RuntimeException(
"Could not find resource '$resource' in any resource paths."
. "(searched: " . join(", ", $this->searchPaths). ")"
);
}
|
Finds a resource, by its relative path, in all available search paths.
The search is performed starting at the last search path, and all the
way back to the first, enabling a cascading-type system of overrides for
all resources.
@param string $resource
@throws RuntimeException If resource cannot be found in any of the available paths
@return string
|
getResource
|
php
|
filp/whoops
|
src/Whoops/Handler/PrettyPageHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PrettyPageHandler.php
|
MIT
|
public function setResourcesPath($resourcesPath)
{
$this->addResourcePath($resourcesPath);
return $this;
}
|
@deprecated
@param string $resourcesPath
@return static
|
setResourcesPath
|
php
|
filp/whoops
|
src/Whoops/Handler/PrettyPageHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PrettyPageHandler.php
|
MIT
|
public function getApplicationPaths()
{
return $this->applicationPaths;
}
|
Return the application paths.
@return array
|
getApplicationPaths
|
php
|
filp/whoops
|
src/Whoops/Handler/PrettyPageHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PrettyPageHandler.php
|
MIT
|
public function setApplicationPaths(array $applicationPaths)
{
$this->applicationPaths = $applicationPaths;
}
|
Set the application paths.
@return void
|
setApplicationPaths
|
php
|
filp/whoops
|
src/Whoops/Handler/PrettyPageHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PrettyPageHandler.php
|
MIT
|
public function setApplicationRootPath($applicationRootPath)
{
$this->templateHelper->setApplicationRootPath($applicationRootPath);
}
|
Set the application root path.
@param string $applicationRootPath
@return void
|
setApplicationRootPath
|
php
|
filp/whoops
|
src/Whoops/Handler/PrettyPageHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PrettyPageHandler.php
|
MIT
|
public function blacklist($superGlobalName, $key)
{
$this->blacklist[$superGlobalName][] = $key;
return $this;
}
|
blacklist a sensitive value within one of the superglobal arrays.
Alias for the hideSuperglobalKey method.
@param string $superGlobalName The name of the superglobal array, e.g. '_GET'
@param string $key The key within the superglobal
@see hideSuperglobalKey
@return static
|
blacklist
|
php
|
filp/whoops
|
src/Whoops/Handler/PrettyPageHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PrettyPageHandler.php
|
MIT
|
public function hideSuperglobalKey($superGlobalName, $key)
{
return $this->blacklist($superGlobalName, $key);
}
|
Hide a sensitive value within one of the superglobal arrays.
@param string $superGlobalName The name of the superglobal array, e.g. '_GET'
@param string $key The key within the superglobal
@return static
|
hideSuperglobalKey
|
php
|
filp/whoops
|
src/Whoops/Handler/PrettyPageHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PrettyPageHandler.php
|
MIT
|
private function masked($superGlobal, $superGlobalName)
{
$blacklisted = $this->blacklist[$superGlobalName];
$values = $superGlobal;
foreach ($blacklisted as $key) {
if (isset($superGlobal[$key])) {
$values[$key] = str_repeat('*', is_string($superGlobal[$key]) ? strlen($superGlobal[$key]) : 3);
}
}
return $values;
}
|
Checks all values within the given superGlobal array.
Blacklisted values will be replaced by a equal length string containing
only '*' characters for string values.
Non-string values will be replaced with a fixed asterisk count.
We intentionally dont rely on $GLOBALS as it depends on the 'auto_globals_jit' php.ini setting.
@param array|\ArrayAccess $superGlobal One of the superglobal arrays
@param string $superGlobalName The name of the superglobal array, e.g. '_GET'
@return array $values without sensitive data
|
masked
|
php
|
filp/whoops
|
src/Whoops/Handler/PrettyPageHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/PrettyPageHandler.php
|
MIT
|
public function addTraceToOutput($returnFrames = null)
{
if (func_num_args() == 0) {
return $this->returnFrames;
}
$this->returnFrames = (bool) $returnFrames;
return $this;
}
|
@param bool|null $returnFrames
@return bool|static
|
addTraceToOutput
|
php
|
filp/whoops
|
src/Whoops/Handler/XmlResponseHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/XmlResponseHandler.php
|
MIT
|
private static function addDataToNode(\SimpleXMLElement $node, $data)
{
assert(is_array($data) || $data instanceof Traversable);
foreach ($data as $key => $value) {
if (is_numeric($key)) {
// Convert the key to a valid string
$key = "unknownNode_". (string) $key;
}
// Delete any char not allowed in XML element names
$key = preg_replace('/[^a-z0-9\-\_\.\:]/i', '', $key);
if (is_array($value)) {
$child = $node->addChild($key);
self::addDataToNode($child, $value);
} else {
$value = str_replace('&', '&', print_r($value, true));
$node->addChild($key, $value);
}
}
return $node;
}
|
@param SimpleXMLElement $node Node to append data to, will be modified in place
@param array|\Traversable $data
@return SimpleXMLElement The modified node, for chaining
|
addDataToNode
|
php
|
filp/whoops
|
src/Whoops/Handler/XmlResponseHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/XmlResponseHandler.php
|
MIT
|
private static function toXml($data)
{
assert(is_array($data) || $data instanceof Traversable);
$node = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><root />");
return self::addDataToNode($node, $data)->asXML();
}
|
The main function for converting to an XML document.
@param array|\Traversable $data
@return string XML
|
toXml
|
php
|
filp/whoops
|
src/Whoops/Handler/XmlResponseHandler.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Handler/XmlResponseHandler.php
|
MIT
|
public static function canSendHeaders()
{
return isset($_SERVER["REQUEST_URI"]) && !headers_sent();
}
|
Can we at this point in time send HTTP headers?
Currently this checks if we are even serving an HTTP request,
as opposed to running from a command line.
If we are serving an HTTP request, we check if it's not too late.
@return bool
|
canSendHeaders
|
php
|
filp/whoops
|
src/Whoops/Util/Misc.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Util/Misc.php
|
MIT
|
public static function isCommandLine()
{
return PHP_SAPI == 'cli';
}
|
Check, if possible, that this execution was triggered by a command line.
@return bool
|
isCommandLine
|
php
|
filp/whoops
|
src/Whoops/Util/Misc.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Util/Misc.php
|
MIT
|
public static function translateErrorCode($error_code)
{
$constants = get_defined_constants(true);
if (array_key_exists('Core', $constants)) {
foreach ($constants['Core'] as $constant => $value) {
if (substr($constant, 0, 2) == 'E_' && $value == $error_code) {
return $constant;
}
}
}
return "E_UNKNOWN";
}
|
Translate ErrorException code into the represented constant.
@param int $error_code
@return string
|
translateErrorCode
|
php
|
filp/whoops
|
src/Whoops/Util/Misc.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Util/Misc.php
|
MIT
|
public static function isLevelFatal($level)
{
$errors = E_ERROR;
$errors |= E_PARSE;
$errors |= E_CORE_ERROR;
$errors |= E_CORE_WARNING;
$errors |= E_COMPILE_ERROR;
$errors |= E_COMPILE_WARNING;
return ($level & $errors) > 0;
}
|
Determine if an error level is fatal (halts execution)
@param int $level
@return bool
|
isLevelFatal
|
php
|
filp/whoops
|
src/Whoops/Util/Misc.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Util/Misc.php
|
MIT
|
public function startOutputBuffering()
{
return ob_start();
}
|
Turns on output buffering.
@return bool
|
startOutputBuffering
|
php
|
filp/whoops
|
src/Whoops/Util/SystemFacade.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Util/SystemFacade.php
|
MIT
|
public function setErrorHandler(callable $handler, $types = 'use-php-defaults')
{
// Since PHP 5.4 the constant E_ALL contains all errors (even E_STRICT)
if ($types === 'use-php-defaults') {
$types = E_ALL;
}
return set_error_handler($handler, $types);
}
|
@param callable $handler
@param int $types
@return callable|null
|
setErrorHandler
|
php
|
filp/whoops
|
src/Whoops/Util/SystemFacade.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Util/SystemFacade.php
|
MIT
|
public function setExceptionHandler(callable $handler)
{
return set_exception_handler($handler);
}
|
@param callable $handler
@return callable|null
|
setExceptionHandler
|
php
|
filp/whoops
|
src/Whoops/Util/SystemFacade.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Util/SystemFacade.php
|
MIT
|
public function escape($raw)
{
$flags = ENT_QUOTES;
// HHVM has all constants defined, but only ENT_IGNORE
// works at the moment
if (defined("ENT_SUBSTITUTE") && !defined("HHVM_VERSION")) {
$flags |= ENT_SUBSTITUTE;
} else {
// This is for 5.3.
// The documentation warns of a potential security issue,
// but it seems it does not apply in our case, because
// we do not blacklist anything anywhere.
$flags |= ENT_IGNORE;
}
$raw = str_replace(chr(9), ' ', $raw);
return htmlspecialchars($raw, $flags, "UTF-8");
}
|
Escapes a string for output in an HTML document
@param string $raw
@return string
|
escape
|
php
|
filp/whoops
|
src/Whoops/Util/TemplateHelper.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Util/TemplateHelper.php
|
MIT
|
public function escapeButPreserveUris($raw)
{
$escaped = $this->escape($raw);
return preg_replace(
"@([A-z]+?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@",
"<a href=\"$1\" target=\"_blank\" rel=\"noreferrer noopener\">$1</a>",
$escaped
);
}
|
Escapes a string for output in an HTML document, but preserves
URIs within it, and converts them to clickable anchor elements.
@param string $raw
@return string
|
escapeButPreserveUris
|
php
|
filp/whoops
|
src/Whoops/Util/TemplateHelper.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Util/TemplateHelper.php
|
MIT
|
public function shorten($path)
{
if ($this->applicationRootPath != "/") {
$path = str_replace($this->applicationRootPath, '…', $path);
}
return $path;
}
|
Replace the part of the path that all files have in common.
@param string $path
@return string
|
shorten
|
php
|
filp/whoops
|
src/Whoops/Util/TemplateHelper.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Util/TemplateHelper.php
|
MIT
|
public function dump($value)
{
$dumper = $this->getDumper();
if ($dumper) {
// re-use the same DumpOutput instance, so it won't re-render the global styles/scripts on each dump.
// exclude verbose information (e.g. exception stack traces)
if (class_exists('Symfony\Component\VarDumper\Caster\Caster')) {
$cloneVar = $this->getCloner()->cloneVar($value, Caster::EXCLUDE_VERBOSE);
// Symfony VarDumper 2.6 Caster class dont exist.
} else {
$cloneVar = $this->getCloner()->cloneVar($value);
}
$dumper->dump(
$cloneVar,
$this->htmlDumperOutput
);
$output = $this->htmlDumperOutput->getOutput();
$this->htmlDumperOutput->clear();
return $output;
}
return htmlspecialchars(print_r($value, true));
}
|
Format the given value into a human readable string.
@param mixed $value
@return string
|
dump
|
php
|
filp/whoops
|
src/Whoops/Util/TemplateHelper.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Util/TemplateHelper.php
|
MIT
|
public function dumpArgs(Frame $frame)
{
// we support frame args only when the optional dumper is available
if (!$this->getDumper()) {
return '';
}
$html = '';
$numFrames = count($frame->getArgs());
if ($numFrames > 0) {
$html = '<ol class="linenums">';
foreach ($frame->getArgs() as $j => $frameArg) {
$html .= '<li>'. $this->dump($frameArg) .'</li>';
}
$html .= '</ol>';
}
return $html;
}
|
Format the args of the given Frame as a human readable html string
@param Frame $frame
@return string the rendered html
|
dumpArgs
|
php
|
filp/whoops
|
src/Whoops/Util/TemplateHelper.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Util/TemplateHelper.php
|
MIT
|
public function slug($original)
{
$slug = str_replace(" ", "-", $original);
$slug = preg_replace('/[^\w\d\-\_]/i', '', $slug);
return strtolower($slug);
}
|
Convert a string to a slug version of itself
@param string $original
@return string
|
slug
|
php
|
filp/whoops
|
src/Whoops/Util/TemplateHelper.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Util/TemplateHelper.php
|
MIT
|
public function render($template, ?array $additionalVariables = null)
{
$variables = $this->getVariables();
// Pass the helper to the template:
$variables["tpl"] = $this;
if ($additionalVariables !== null) {
$variables = array_replace($variables, $additionalVariables);
}
call_user_func(function () {
extract(func_get_arg(1));
require func_get_arg(0);
}, $template, $variables);
}
|
Given a template path, render it within its own scope. This
method also accepts an array of additional variables to be
passed to the template.
@param string $template
|
render
|
php
|
filp/whoops
|
src/Whoops/Util/TemplateHelper.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Util/TemplateHelper.php
|
MIT
|
public function setVariables(array $variables)
{
$this->variables = $variables;
}
|
Sets the variables to be passed to all templates rendered
by this template helper.
|
setVariables
|
php
|
filp/whoops
|
src/Whoops/Util/TemplateHelper.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Util/TemplateHelper.php
|
MIT
|
public function setVariable($variableName, $variableValue)
{
$this->variables[$variableName] = $variableValue;
}
|
Sets a single template variable, by its name:
@param string $variableName
@param mixed $variableValue
|
setVariable
|
php
|
filp/whoops
|
src/Whoops/Util/TemplateHelper.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Util/TemplateHelper.php
|
MIT
|
public function getVariable($variableName, $defaultValue = null)
{
return isset($this->variables[$variableName]) ?
$this->variables[$variableName] : $defaultValue;
}
|
Gets a single template variable, by its name, or
$defaultValue if the variable does not exist
@param string $variableName
@param mixed $defaultValue
@return mixed
|
getVariable
|
php
|
filp/whoops
|
src/Whoops/Util/TemplateHelper.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Util/TemplateHelper.php
|
MIT
|
public function delVariable($variableName)
{
unset($this->variables[$variableName]);
}
|
Unsets a single template variable, by its name
@param string $variableName
|
delVariable
|
php
|
filp/whoops
|
src/Whoops/Util/TemplateHelper.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Util/TemplateHelper.php
|
MIT
|
public function getVariables()
{
return $this->variables;
}
|
Returns all variables for this helper
@return array
|
getVariables
|
php
|
filp/whoops
|
src/Whoops/Util/TemplateHelper.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Util/TemplateHelper.php
|
MIT
|
public function setCloner($cloner)
{
$this->cloner = $cloner;
}
|
Set the cloner used for dumping variables.
@param AbstractCloner $cloner
|
setCloner
|
php
|
filp/whoops
|
src/Whoops/Util/TemplateHelper.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Util/TemplateHelper.php
|
MIT
|
public function getCloner()
{
if (!$this->cloner) {
$this->cloner = new VarCloner();
}
return $this->cloner;
}
|
Get the cloner used for dumping variables.
@return AbstractCloner
|
getCloner
|
php
|
filp/whoops
|
src/Whoops/Util/TemplateHelper.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Util/TemplateHelper.php
|
MIT
|
public function setApplicationRootPath($applicationRootPath)
{
$this->applicationRootPath = $applicationRootPath;
}
|
Set the application root path.
@param string $applicationRootPath
|
setApplicationRootPath
|
php
|
filp/whoops
|
src/Whoops/Util/TemplateHelper.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Util/TemplateHelper.php
|
MIT
|
public function getApplicationRootPath()
{
return $this->applicationRootPath;
}
|
Return the application root path.
@return string
|
getApplicationRootPath
|
php
|
filp/whoops
|
src/Whoops/Util/TemplateHelper.php
|
https://github.com/filp/whoops/blob/master/src/Whoops/Util/TemplateHelper.php
|
MIT
|
public function testPopHandler()
{
$run = $this->getRunInstance();
$handlerOne = $this->getHandler();
$handlerTwo = $this->getHandler();
$handlerThree = $this->getHandler();
$run->pushHandler($handlerOne);
$run->pushHandler($handlerTwo);
$run->pushHandler($handlerThree);
$this->assertSame($handlerThree, $run->popHandler());
$this->assertSame($handlerTwo, $run->popHandler());
$this->assertSame($handlerOne, $run->popHandler());
// Should return null if there's nothing else in
// the stack
$this->assertNull($run->popHandler());
// Should be empty since we popped everything off
// the stack:
$this->assertEmpty($run->getHandlers());
}
|
@covers Whoops\Run::popHandler
@covers Whoops\Run::getHandlers
|
testPopHandler
|
php
|
filp/whoops
|
tests/Whoops/RunTest.php
|
https://github.com/filp/whoops/blob/master/tests/Whoops/RunTest.php
|
MIT
|
public function testRemoveHandler()
{
$run = $this->getRunInstance();
$handlerOne = $this->getHandler();
$handlerTwo = $this->getHandler();
$handlerThree = $this->getHandler();
$run->pushHandler($handlerOne);
$run->pushHandler($handlerTwo);
$run->pushHandler($handlerThree);
$run->removeLastHandler();
$this->assertSame($handlerTwo, $run->getHandlers()[0]);
$run->removeFirstHandler();
$this->assertSame($handlerTwo, $run->getHandlers()[0]);
$this->assertCount(1, $run->getHandlers());
}
|
@covers Whoops\Run::removeFirstHandler
@covers Whoops\Run::removeLastHandler
@covers Whoops\Run::getHandlers
|
testRemoveHandler
|
php
|
filp/whoops
|
tests/Whoops/RunTest.php
|
https://github.com/filp/whoops/blob/master/tests/Whoops/RunTest.php
|
MIT
|
public function testHandlerHoldsOrder()
{
$run = $this->getRunInstance();
$handlerOne = $this->getHandler();
$handlerTwo = $this->getHandler();
$handlerThree = $this->getHandler();
$handlerFour = $this->getHandler();
$run->pushHandler($handlerOne);
$run->prependHandler($handlerTwo);
$run->appendHandler($handlerThree);
$run->appendHandler($handlerFour);
$handlers = $run->getHandlers();
$this->assertSame($handlers[0], $handlerFour);
$this->assertSame($handlers[1], $handlerThree);
$this->assertSame($handlers[2], $handlerOne);
$this->assertSame($handlers[3], $handlerTwo);
}
|
@covers Whoops\Run::pushHandler
@covers Whoops\Run::getHandlers
|
testHandlerHoldsOrder
|
php
|
filp/whoops
|
tests/Whoops/RunTest.php
|
https://github.com/filp/whoops/blob/master/tests/Whoops/RunTest.php
|
MIT
|
public function testHandlersGonnaHandle()
{
$run = $this->getRunInstance();
$exception = $this->getException();
$order = new ArrayObject();
$handlerOne = $this->getHandler();
$handlerTwo = $this->getHandler();
$handlerThree = $this->getHandler();
$handlerOne->shouldReceive('handle')
->andReturnUsing(function () use ($order) { $order[] = 1; });
$handlerTwo->shouldReceive('handle')
->andReturnUsing(function () use ($order) { $order[] = 2; });
$handlerThree->shouldReceive('handle')
->andReturnUsing(function () use ($order) { $order[] = 3; });
$run->pushHandler($handlerOne);
$run->pushHandler($handlerTwo);
$run->pushHandler($handlerThree);
// Get an exception to be handled, and verify that the handlers
// are given the handler, and in the inverse order they were
// registered.
$run->handleException($exception);
$this->assertEquals((array) $order, [3, 2, 1]);
}
|
@todo possibly split this up a bit and move
some of this test to Handler unit tests?
@covers Whoops\Run::handleException
|
testHandlersGonnaHandle
|
php
|
filp/whoops
|
tests/Whoops/RunTest.php
|
https://github.com/filp/whoops/blob/master/tests/Whoops/RunTest.php
|
MIT
|
public function testErrorReporting()
{
$run = $this->getRunInstance();
$run->register();
$handler = $this->getHandler();
$run->pushHandler($handler);
$test = $this;
$handler
->shouldReceive('handle')
->andReturnUsing(function () use ($test) {
$test->fail('$handler should not be called, error_reporting not respected');
});
$oldLevel = error_reporting(E_ALL ^ E_USER_NOTICE);
trigger_error("Test error reporting", E_USER_NOTICE);
error_reporting($oldLevel);
// Reached the end without errors
$this->assertTrue(true);
}
|
Test to make sure that error_reporting is respected.
|
testErrorReporting
|
php
|
filp/whoops
|
tests/Whoops/RunTest.php
|
https://github.com/filp/whoops/blob/master/tests/Whoops/RunTest.php
|
MIT
|
public function testGetSilencedError()
{
$run = $this->getRunInstance();
$run->register();
$handler = $this->getHandler();
$run->pushHandler($handler);
@strpos();
$error = error_get_last();
$this->assertTrue($error && strpos($error['message'], 'strpos()') !== false);
}
|
@covers Whoops\Run::handleError
@requires PHP < 8
|
testGetSilencedError
|
php
|
filp/whoops
|
tests/Whoops/RunTest.php
|
https://github.com/filp/whoops/blob/master/tests/Whoops/RunTest.php
|
MIT
|
public function testErrorWrappedInException()
{
try {
$run = $this->getRunInstance();
$run->handleError(E_WARNING, 'my message', 'my file', 99);
$this->fail("missing expected exception");
} catch (\ErrorException $e) {
$this->assertSame(E_WARNING, $e->getSeverity());
$this->assertSame(E_WARNING, $e->getCode(), "For BC reasons getCode() should match getSeverity()");
$this->assertSame('my message', $e->getMessage());
$this->assertSame('my file', $e->getFile());
$this->assertSame(99, $e->getLine());
}
}
|
@covers Whoops\Run::handleError
@see https://github.com/filp/whoops/issues/267
|
testErrorWrappedInException
|
php
|
filp/whoops
|
tests/Whoops/RunTest.php
|
https://github.com/filp/whoops/blob/master/tests/Whoops/RunTest.php
|
MIT
|
public function testOutputIsSent()
{
$run = $this->getRunInstance();
$run->pushHandler(function () {
echo "hello there";
});
ob_start();
$run->handleException(new RuntimeException());
$this->assertEquals("hello there", ob_get_clean());
}
|
@covers Whoops\Run::handleException
@covers Whoops\Run::writeToOutput
|
testOutputIsSent
|
php
|
filp/whoops
|
tests/Whoops/RunTest.php
|
https://github.com/filp/whoops/blob/master/tests/Whoops/RunTest.php
|
MIT
|
public function testOutputIsNotSent()
{
$run = $this->getRunInstance();
$run->writeToOutput(false);
$run->pushHandler(function () {
echo "hello there";
});
ob_start();
$this->assertEquals("hello there", $run->handleException(new RuntimeException()));
$this->assertEquals("", ob_get_clean());
}
|
@covers Whoops\Run::handleException
@covers Whoops\Run::writeToOutput
|
testOutputIsNotSent
|
php
|
filp/whoops
|
tests/Whoops/RunTest.php
|
https://github.com/filp/whoops/blob/master/tests/Whoops/RunTest.php
|
MIT
|
public function testAddFrameFilter()
{
$run = $this->getRunInstance();
$filterCallbackOne = function(Frame $frame) {};
$filterCallbackTwo = function(Frame $frame) {};
$run
->addFrameFilter($filterCallbackOne)
->addFrameFilter($filterCallbackTwo);
$frameFilters = $run->getFrameFilters();
$this->assertCount(2, $frameFilters);
$this->assertContains($filterCallbackOne, $frameFilters);
$this->assertContains($filterCallbackTwo, $frameFilters);
$this->assertInstanceOf("Whoops\\RunInterface", $run);
}
|
@covers Whoops\Run::addFrameFilter
@covers Whoops\Run::getFrameFilters
|
testAddFrameFilter
|
php
|
filp/whoops
|
tests/Whoops/RunTest.php
|
https://github.com/filp/whoops/blob/master/tests/Whoops/RunTest.php
|
MIT
|
public function testClearFrameFilters()
{
$run = $this->getRunInstance();
$run->addFrameFilter(function(Frame $frame) {});
$run = $run->clearFrameFilters();
$this->assertEmpty($run->getFrameFilters());
$this->assertInstanceOf("Whoops\\RunInterface", $run);
}
|
@covers Whoops\Run::clearFrameFilters
@covers Whoops\Run::getFrameFilters
|
testClearFrameFilters
|
php
|
filp/whoops
|
tests/Whoops/RunTest.php
|
https://github.com/filp/whoops/blob/master/tests/Whoops/RunTest.php
|
MIT
|
protected function assertStringContains($a, $b)
{
if (method_exists($this, 'assertStringContainsString')) {
$this->assertStringContainsString($a, $b);
} else {
$this->assertContains($a, $b);
}
}
|
@param string $a
@param string $b
@return void
|
assertStringContains
|
php
|
filp/whoops
|
tests/Whoops/TestCase.php
|
https://github.com/filp/whoops/blob/master/tests/Whoops/TestCase.php
|
MIT
|
protected function assertStringNotContains($a, $b)
{
if (method_exists($this, 'assertStringNotContainsString')) {
$this->assertStringNotContainsString($a, $b);
} else {
$this->assertNotContains($a, $b);
}
}
|
@param string $a
@param string $b
@return void
|
assertStringNotContains
|
php
|
filp/whoops
|
tests/Whoops/TestCase.php
|
https://github.com/filp/whoops/blob/master/tests/Whoops/TestCase.php
|
MIT
|
public static function callPrivateMethod($class_or_object, $method, $args = [])
{
$ref = new \ReflectionMethod($class_or_object, $method);
$ref->setAccessible(true);
$object = is_object($class_or_object) ? $class_or_object : null;
return $ref->invokeArgs($object, $args);
}
|
@param object|string $class_or_object
@param string $method
@param mixed[] $args
@return mixed
|
callPrivateMethod
|
php
|
filp/whoops
|
tests/Whoops/TestCase.php
|
https://github.com/filp/whoops/blob/master/tests/Whoops/TestCase.php
|
MIT
|
private function getFrameCollectionInstance($frames = null)
{
if ($frames === null) {
$frames = $this->getFrameDataList(10);
}
return new FrameCollection($frames);
}
|
@param array $frames
@return \Whoops\Exception\FrameCollection
|
getFrameCollectionInstance
|
php
|
filp/whoops
|
tests/Whoops/Exception/FrameCollectionTest.php
|
https://github.com/filp/whoops/blob/master/tests/Whoops/Exception/FrameCollectionTest.php
|
MIT
|
public function testFilterFrames()
{
$frames = $this->getFrameCollectionInstance();
// Filter out all frames with a line number under 6
$frames->filter(function ($frame) {
return $frame->getLine() <= 5;
});
$this->assertCount(5, $frames);
}
|
@covers Whoops\Exception\FrameCollection::filter
@covers Whoops\Exception\FrameCollection::count
|
testFilterFrames
|
php
|
filp/whoops
|
tests/Whoops/Exception/FrameCollectionTest.php
|
https://github.com/filp/whoops/blob/master/tests/Whoops/Exception/FrameCollectionTest.php
|
MIT
|
public function testCollectionIsSerializable()
{
$frames = $this->getFrameCollectionInstance();
$serializedFrames = serialize($frames);
$newFrames = unserialize($serializedFrames);
foreach ($newFrames as $frame) {
$this->assertInstanceOf('Whoops\\Exception\\Frame', $frame);
}
}
|
@covers Whoops\Exception\FrameCollection::serialize
@covers Whoops\Exception\FrameCollection::unserialize
|
testCollectionIsSerializable
|
php
|
filp/whoops
|
tests/Whoops/Exception/FrameCollectionTest.php
|
https://github.com/filp/whoops/blob/master/tests/Whoops/Exception/FrameCollectionTest.php
|
MIT
|
public function testGetFileContentsWhenFrameIsNotRelatedToSpecificFile($fakeFilename)
{
$data = array_merge($this->getFrameData(), ['file' => $fakeFilename]);
$frame = $this->getFrameInstance($data);
$this->assertNull($frame->getFileContents());
}
|
@covers Whoops\Exception\Frame::getFileContents
@testWith ["[internal]"]
["Unknown"]
@see https://github.com/filp/whoops/pull/599
|
testGetFileContentsWhenFrameIsNotRelatedToSpecificFile
|
php
|
filp/whoops
|
tests/Whoops/Exception/FrameTest.php
|
https://github.com/filp/whoops/blob/master/tests/Whoops/Exception/FrameTest.php
|
MIT
|
public function testGetComments()
{
$frame = $this->getFrameInstance();
$testComments = [
'Dang, yo!',
'Errthangs broken!',
'Dayumm!',
];
$frame->addComment($testComments[0]);
$frame->addComment($testComments[1]);
$frame->addComment($testComments[2]);
$comments = $frame->getComments();
$this->assertCount(3, $comments);
$this->assertEquals($comments[0]['comment'], $testComments[0]);
$this->assertEquals($comments[1]['comment'], $testComments[1]);
$this->assertEquals($comments[2]['comment'], $testComments[2]);
}
|
@covers Whoops\Exception\Frame::addComment
@covers Whoops\Exception\Frame::getComments
|
testGetComments
|
php
|
filp/whoops
|
tests/Whoops/Exception/FrameTest.php
|
https://github.com/filp/whoops/blob/master/tests/Whoops/Exception/FrameTest.php
|
MIT
|
public function testGetFilteredComments()
{
$frame = $this->getFrameInstance();
$testComments = [
['Dang, yo!', 'test'],
['Errthangs broken!', 'test'],
'Dayumm!',
];
$frame->addComment($testComments[0][0], $testComments[0][1]);
$frame->addComment($testComments[1][0], $testComments[1][1]);
$frame->addComment($testComments[2][0], $testComments[2][1]);
$comments = $frame->getComments('test');
$this->assertCount(2, $comments);
$this->assertEquals($comments[0]['comment'], $testComments[0][0]);
$this->assertEquals($comments[1]['comment'], $testComments[1][0]);
}
|
@covers Whoops\Exception\Frame::addComment
@covers Whoops\Exception\Frame::getComments
|
testGetFilteredComments
|
php
|
filp/whoops
|
tests/Whoops/Exception/FrameTest.php
|
https://github.com/filp/whoops/blob/master/tests/Whoops/Exception/FrameTest.php
|
MIT
|
public function testFrameIsSerializable()
{
$data = $this->getFrameData();
$frame = $this->getFrameInstance();
$commentText = "Gee I hope this works";
$commentContext = "test";
$frame->addComment($commentText, $commentContext);
$serializedFrame = serialize($frame);
$newFrame = unserialize($serializedFrame);
$this->assertInstanceOf('Whoops\\Exception\\Frame', $newFrame);
$this->assertEquals($newFrame->getFile(), $data['file']);
$this->assertEquals($newFrame->getLine(), $data['line']);
$comments = $newFrame->getComments();
$this->assertCount(1, $comments);
$this->assertEquals($comments[0]["comment"], $commentText);
$this->assertEquals($comments[0]["context"], $commentContext);
}
|
@covers Whoops\Exception\Frame::serialize
@covers Whoops\Exception\Frame::unserialize
|
testFrameIsSerializable
|
php
|
filp/whoops
|
tests/Whoops/Exception/FrameTest.php
|
https://github.com/filp/whoops/blob/master/tests/Whoops/Exception/FrameTest.php
|
MIT
|
protected function getException($message = "", $code = 0, $previous = null)
{
return new Exception($message, $code, $previous);
}
|
@param string $message
@param int $code
@param Exception $previous
@return Exception
|
getException
|
php
|
filp/whoops
|
tests/Whoops/Exception/InspectorTest.php
|
https://github.com/filp/whoops/blob/master/tests/Whoops/Exception/InspectorTest.php
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.