Update Composer packages

This commit is contained in:
Paul Nicoué 2023-04-14 16:30:28 +02:00
parent d482354bdf
commit e7e7361480
219 changed files with 6487 additions and 4444 deletions

View file

@ -6,16 +6,19 @@
namespace Whoops\Exception;
use Whoops\Inspector\InspectorInterface;
class Formatter
{
/**
* Returns all basic information about the exception in a simple array
* for further convertion to other languages
* @param Inspector $inspector
* @param bool $shouldAddTrace
* @param InspectorInterface $inspector
* @param bool $shouldAddTrace
* @param array<callable> $frameFilters
* @return array
*/
public static function formatExceptionAsDataArray(Inspector $inspector, $shouldAddTrace)
public static function formatExceptionAsDataArray(InspectorInterface $inspector, $shouldAddTrace, array $frameFilters = [])
{
$exception = $inspector->getException();
$response = [
@ -27,7 +30,7 @@ class Formatter
];
if ($shouldAddTrace) {
$frames = $inspector->getFrames();
$frames = $inspector->getFrames($frameFilters);
$frameData = [];
foreach ($frames as $frame) {
@ -47,7 +50,7 @@ class Formatter
return $response;
}
public static function formatExceptionPlain(Inspector $inspector)
public static function formatExceptionPlain(InspectorInterface $inspector)
{
$message = $inspector->getException()->getMessage();
$frames = $inspector->getFrames();

View file

@ -31,9 +31,6 @@ class Frame implements Serializable
*/
protected $application;
/**
* @param array[]
*/
public function __construct(array $frame)
{
$this->frame = $frame;

View file

@ -25,9 +25,6 @@ class FrameCollection implements ArrayAccess, IteratorAggregate, Serializable, C
*/
private $frames;
/**
* @param array $frames
*/
public function __construct(array $frames)
{
$this->frames = array_map(function ($frame) {

View file

@ -6,9 +6,11 @@
namespace Whoops\Exception;
use Whoops\Inspector\InspectorFactory;
use Whoops\Inspector\InspectorInterface;
use Whoops\Util\Misc;
class Inspector
class Inspector implements InspectorInterface
{
/**
* @var \Throwable
@ -31,11 +33,18 @@ class Inspector
private $previousExceptions;
/**
* @param \Throwable $exception The exception to inspect
* @var \Whoops\Inspector\InspectorFactoryInterface|null
*/
public function __construct($exception)
protected $inspectorFactory;
/**
* @param \Throwable $exception The exception to inspect
* @param \Whoops\Inspector\InspectorFactoryInterface $factory
*/
public function __construct($exception, $factory = null)
{
$this->exception = $exception;
$this->inspectorFactory = $factory ?: new InspectorFactory();
}
/**
@ -137,7 +146,7 @@ class Inspector
$previousException = $this->exception->getPrevious();
if ($previousException) {
$this->previousExceptionInspector = new Inspector($previousException);
$this->previousExceptionInspector = $this->inspectorFactory->create($previousException);
}
}
@ -167,9 +176,12 @@ class Inspector
/**
* Returns an iterator for the inspected exception's
* frames.
*
* @param array<callable> $frameFilters
*
* @return \Whoops\Exception\FrameCollection
*/
public function getFrames()
public function getFrames(array $frameFilters = [])
{
if ($this->frames === null) {
$frames = $this->getTrace($this->exception);
@ -225,6 +237,13 @@ class Inspector
$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;
@ -301,7 +320,6 @@ class Inspector
* 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)
*
* @param array $frame
* @return bool
*/
protected function isValidNextFrame(array $frame)

View file

@ -6,7 +6,7 @@
namespace Whoops\Handler;
use Whoops\Exception\Inspector;
use Whoops\Inspector\InspectorInterface;
use Whoops\RunInterface;
/**
@ -36,7 +36,7 @@ abstract class Handler implements HandlerInterface
private $run;
/**
* @var Inspector $inspector
* @var InspectorInterface $inspector
*/
private $inspector;
@ -62,15 +62,15 @@ abstract class Handler implements HandlerInterface
}
/**
* @param Inspector $inspector
* @param InspectorInterface $inspector
*/
public function setInspector(Inspector $inspector)
public function setInspector(InspectorInterface $inspector)
{
$this->inspector = $inspector;
}
/**
* @return Inspector
* @return InspectorInterface
*/
protected function getInspector()
{

View file

@ -6,7 +6,7 @@
namespace Whoops\Handler;
use Whoops\Exception\Inspector;
use Whoops\Inspector\InspectorInterface;
use Whoops\RunInterface;
interface HandlerInterface
@ -29,8 +29,8 @@ interface HandlerInterface
public function setException($exception);
/**
* @param Inspector $inspector
* @param InspectorInterface $inspector
* @return void
*/
public function setInspector(Inspector $inspector);
public function setInspector(InspectorInterface $inspector);
}

View file

@ -60,7 +60,8 @@ class JsonResponseHandler extends Handler
'errors' => [
Formatter::formatExceptionAsDataArray(
$this->getInspector(),
$this->addTraceToOutput()
$this->addTraceToOutput(),
$this->getRun()->getFrameFilters()
),
]
];
@ -68,7 +69,8 @@ class JsonResponseHandler extends Handler
$response = [
'error' => Formatter::formatExceptionAsDataArray(
$this->getInspector(),
$this->addTraceToOutput()
$this->addTraceToOutput(),
$this->getRun()->getFrameFilters()
),
];
}

View file

@ -282,7 +282,7 @@ class PlainTextHandler extends Handler
return '';
}
$inspector = $this->getInspector();
$frames = $inspector->getFrames();
$frames = $inspector->getFrames($this->getRun()->getFrameFilters());
$response = "\nStack trace:";

View file

@ -287,6 +287,7 @@ class PrettyPageHandler extends Handler
$vars["tables"] = array_merge($extraTables, $vars["tables"]);
$plainTextHandler = new PlainTextHandler();
$plainTextHandler->setRun($this->getRun());
$plainTextHandler->setException($this->getException());
$plainTextHandler->setInspector($this->getInspector());
$vars["preface"] = "<!--\n\n\n" . $this->templateHelper->escape($plainTextHandler->generateResponse()) . "\n\n\n\n\n\n\n\n\n\n\n-->";
@ -304,7 +305,7 @@ class PrettyPageHandler extends Handler
*/
protected function getExceptionFrames()
{
$frames = $this->getInspector()->getFrames();
$frames = $this->getInspector()->getFrames($this->getRun()->getFrameFilters());
if ($this->getApplicationPaths()) {
foreach ($frames as $frame) {
@ -353,7 +354,6 @@ class PrettyPageHandler extends Handler
* will be flattened with `print_r`.
*
* @param string $label
* @param array $data
*
* @return static
*/
@ -383,7 +383,7 @@ class PrettyPageHandler extends Handler
throw new InvalidArgumentException('Expecting callback argument to be callable');
}
$this->extraTables[$label] = function (\Whoops\Exception\Inspector $inspector = null) use ($callback) {
$this->extraTables[$label] = function (\Whoops\Inspector\InspectorInterface $inspector = null) use ($callback) {
try {
$result = call_user_func($callback, $inspector);
@ -755,11 +755,9 @@ class PrettyPageHandler extends Handler
/**
* Set the application paths.
*
* @param array $applicationPaths
*
* @return void
*/
public function setApplicationPaths($applicationPaths)
public function setApplicationPaths(array $applicationPaths)
{
$this->applicationPaths = $applicationPaths;
}

View file

@ -43,7 +43,8 @@ class XmlResponseHandler extends Handler
$response = [
'error' => Formatter::formatExceptionAsDataArray(
$this->getInspector(),
$this->addTraceToOutput()
$this->addTraceToOutput(),
$this->getRun()->getFrameFilters()
),
];

View file

@ -0,0 +1,21 @@
<?php
/**
* Whoops - php errors for cool kids
* @author Filipe Dobreira <http://github.com/filp>
*/
namespace Whoops\Inspector;
use Whoops\Exception\Inspector;
class InspectorFactory implements InspectorFactoryInterface
{
/**
* @param \Throwable $exception
* @return InspectorInterface
*/
public function create($exception)
{
return new Inspector($exception, $this);
}
}

View file

@ -0,0 +1,16 @@
<?php
/**
* Whoops - php errors for cool kids
* @author Filipe Dobreira <http://github.com/filp>
*/
namespace Whoops\Inspector;
interface InspectorFactoryInterface
{
/**
* @param \Throwable $exception
* @return InspectorInterface
*/
public function create($exception);
}

View file

@ -0,0 +1,71 @@
<?php
/**
* Whoops - php errors for cool kids
* @author Filipe Dobreira <http://github.com/filp>
*/
namespace Whoops\Inspector;
interface InspectorInterface
{
/**
* @return \Throwable
*/
public function getException();
/**
* @return string
*/
public function getExceptionName();
/**
* @return string
*/
public function getExceptionMessage();
/**
* @return string[]
*/
public function getPreviousExceptionMessages();
/**
* @return int[]
*/
public function getPreviousExceptionCodes();
/**
* Returns a url to the php-manual related to the underlying error - when available.
*
* @return string|null
*/
public function getExceptionDocrefUrl();
/**
* Does the wrapped Exception has a previous Exception?
* @return bool
*/
public function hasPreviousException();
/**
* Returns an Inspector for a previous Exception, if any.
* @todo Clean this up a bit, cache stuff a bit better.
* @return InspectorInterface
*/
public function getPreviousExceptionInspector();
/**
* Returns an array of all previous exceptions for this inspector's exception
* @return \Throwable[]
*/
public function getPreviousExceptions();
/**
* Returns an iterator for the inspected exception's
* frames.
*
* @param array<callable> $frameFilters
*
* @return \Whoops\Exception\FrameCollection
*/
public function getFrames(array $frameFilters = []);
}

View file

@ -9,10 +9,13 @@ namespace Whoops;
use InvalidArgumentException;
use Throwable;
use Whoops\Exception\ErrorException;
use Whoops\Exception\Inspector;
use Whoops\Handler\CallbackHandler;
use Whoops\Handler\Handler;
use Whoops\Handler\HandlerInterface;
use Whoops\Inspector\CallableInspectorFactory;
use Whoops\Inspector\InspectorFactory;
use Whoops\Inspector\InspectorFactoryInterface;
use Whoops\Inspector\InspectorInterface;
use Whoops\Util\Misc;
use Whoops\Util\SystemFacade;
@ -66,9 +69,22 @@ final class Run implements RunInterface
*/
private $canThrowExceptions = true;
/**
* The inspector factory to create inspectors.
*
* @var InspectorFactoryInterface
*/
private $inspectorFactory;
/**
* @var array<callable>
*/
private $frameFilters = [];
public function __construct(SystemFacade $system = null)
{
$this->system = $system ?: new SystemFacade;
$this->inspectorFactory = new InspectorFactory();
}
/**
@ -165,6 +181,17 @@ final class Run implements RunInterface
return $this;
}
public function getFrameFilters()
{
return $this->frameFilters;
}
public function clearFrameFilters()
{
$this->frameFilters = [];
return $this;
}
/**
* Registers this instance as an error handler.
*
@ -179,6 +206,7 @@ final class Run implements RunInterface
class_exists("\\Whoops\\Exception\\FrameCollection");
class_exists("\\Whoops\\Exception\\Frame");
class_exists("\\Whoops\\Exception\\Inspector");
class_exists("\\Whoops\\Inspector\\InspectorFactory");
$this->system->setErrorHandler([$this, self::ERROR_HANDLER]);
$this->system->setExceptionHandler([$this, self::EXCEPTION_HANDLER]);
@ -488,14 +516,38 @@ final class Run implements RunInterface
}
}
/**
* @param InspectorFactoryInterface $factory
*
* @return void
*/
public function setInspectorFactory(InspectorFactoryInterface $factory)
{
$this->inspectorFactory = $factory;
}
public function addFrameFilter($filterCallback)
{
if (!is_callable($filterCallback)) {
throw new \InvalidArgumentException(sprintf(
"A frame filter must be of type callable, %s type given.",
gettype($filterCallback)
));
}
$this->frameFilters[] = $filterCallback;
return $this;
}
/**
* @param Throwable $exception
*
* @return Inspector
* @return InspectorInterface
*/
private function getInspector($exception)
{
return new Inspector($exception);
return $this->inspectorFactory->create($exception);
}
/**

View file

@ -49,6 +49,16 @@ interface RunInterface
*/
public function clearHandlers();
/**
* @return array<callable>
*/
public function getFrameFilters();
/**
* @return Run
*/
public function clearFrameFilters();
/**
* Registers this instance as an error handler.
*
@ -137,4 +147,12 @@ interface RunInterface
* Special case to deal with Fatal errors and the like.
*/
public function handleShutdown();
/**
* Registers a filter callback in the frame filters stack.
*
* @param callable $filterCallback
* @return \Whoops\Run
*/
public function addFrameFilter($filterCallback);
}

View file

@ -232,7 +232,6 @@ class TemplateHelper
* passed to the template.
*
* @param string $template
* @param array $additionalVariables
*/
public function render($template, array $additionalVariables = null)
{
@ -254,8 +253,6 @@ class TemplateHelper
/**
* Sets the variables to be passed to all templates rendered
* by this template helper.
*
* @param array $variables
*/
public function setVariables(array $variables)
{