mirror of
https://github.com/linuxserver/Heimdall.git
synced 2025-12-09 08:23:53 +09:00
Update dependencies
This commit is contained in:
@@ -14,6 +14,10 @@ namespace Symfony\Component\ErrorHandler\Exception;
|
||||
use Symfony\Component\HttpFoundation\Exception\RequestExceptionInterface;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
|
||||
use Symfony\Component\VarDumper\Caster\Caster;
|
||||
use Symfony\Component\VarDumper\Cloner\Data;
|
||||
use Symfony\Component\VarDumper\Cloner\Stub;
|
||||
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||
|
||||
/**
|
||||
* FlattenException wraps a PHP Error or Exception to be able to serialize it.
|
||||
@@ -24,54 +28,26 @@ use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
|
||||
*/
|
||||
class FlattenException
|
||||
{
|
||||
/** @var string */
|
||||
private $message;
|
||||
private string $message;
|
||||
private string|int $code;
|
||||
private ?self $previous = null;
|
||||
private array $trace;
|
||||
private string $traceAsString;
|
||||
private string $class;
|
||||
private int $statusCode;
|
||||
private string $statusText;
|
||||
private array $headers;
|
||||
private string $file;
|
||||
private int $line;
|
||||
private ?string $asString = null;
|
||||
private Data $dataRepresentation;
|
||||
|
||||
/** @var int|string */
|
||||
private $code;
|
||||
|
||||
/** @var self|null */
|
||||
private $previous;
|
||||
|
||||
/** @var array */
|
||||
private $trace;
|
||||
|
||||
/** @var string */
|
||||
private $traceAsString;
|
||||
|
||||
/** @var string */
|
||||
private $class;
|
||||
|
||||
/** @var int */
|
||||
private $statusCode;
|
||||
|
||||
/** @var string */
|
||||
private $statusText;
|
||||
|
||||
/** @var array */
|
||||
private $headers;
|
||||
|
||||
/** @var string */
|
||||
private $file;
|
||||
|
||||
/** @var int */
|
||||
private $line;
|
||||
|
||||
/** @var string|null */
|
||||
private $asString;
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function create(\Exception $exception, int $statusCode = null, array $headers = []): self
|
||||
public static function create(\Exception $exception, ?int $statusCode = null, array $headers = []): static
|
||||
{
|
||||
return static::createFromThrowable($exception, $statusCode, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function createFromThrowable(\Throwable $exception, int $statusCode = null, array $headers = []): self
|
||||
public static function createFromThrowable(\Throwable $exception, ?int $statusCode = null, array $headers = []): static
|
||||
{
|
||||
$e = new static();
|
||||
$e->setMessage($exception->getMessage());
|
||||
@@ -84,9 +60,7 @@ class FlattenException
|
||||
$statusCode = 400;
|
||||
}
|
||||
|
||||
if (null === $statusCode) {
|
||||
$statusCode = 500;
|
||||
}
|
||||
$statusCode ??= 500;
|
||||
|
||||
if (class_exists(Response::class) && isset(Response::$statusTexts[$statusCode])) {
|
||||
$statusText = Response::$statusTexts[$statusCode];
|
||||
@@ -98,7 +72,7 @@ class FlattenException
|
||||
$e->setStatusCode($statusCode);
|
||||
$e->setHeaders($headers);
|
||||
$e->setTraceFromThrowable($exception);
|
||||
$e->setClass(\get_class($exception));
|
||||
$e->setClass(get_debug_type($exception));
|
||||
$e->setFile($exception->getFile());
|
||||
$e->setLine($exception->getLine());
|
||||
|
||||
@@ -111,6 +85,33 @@ class FlattenException
|
||||
return $e;
|
||||
}
|
||||
|
||||
public static function createWithDataRepresentation(\Throwable $throwable, ?int $statusCode = null, array $headers = [], ?VarCloner $cloner = null): static
|
||||
{
|
||||
$e = static::createFromThrowable($throwable, $statusCode, $headers);
|
||||
|
||||
static $defaultCloner;
|
||||
|
||||
if (!$cloner ??= $defaultCloner) {
|
||||
$cloner = $defaultCloner = new VarCloner();
|
||||
$cloner->addCasters([
|
||||
\Throwable::class => function (\Throwable $e, array $a, Stub $s, bool $isNested): array {
|
||||
if (!$isNested) {
|
||||
unset($a[Caster::PREFIX_PROTECTED.'message']);
|
||||
unset($a[Caster::PREFIX_PROTECTED.'code']);
|
||||
unset($a[Caster::PREFIX_PROTECTED.'file']);
|
||||
unset($a[Caster::PREFIX_PROTECTED.'line']);
|
||||
unset($a["\0Error\0trace"], $a["\0Exception\0trace"]);
|
||||
unset($a["\0Error\0previous"], $a["\0Exception\0previous"]);
|
||||
}
|
||||
|
||||
return $a;
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
return $e->setDataRepresentation($cloner->cloneVar($throwable));
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
$exceptions = [];
|
||||
@@ -119,6 +120,7 @@ class FlattenException
|
||||
'message' => $exception->getMessage(),
|
||||
'class' => $exception->getClass(),
|
||||
'trace' => $exception->getTrace(),
|
||||
'data' => $exception->getDataRepresentation(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -133,7 +135,7 @@ class FlattenException
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setStatusCode(int $code): self
|
||||
public function setStatusCode(int $code): static
|
||||
{
|
||||
$this->statusCode = $code;
|
||||
|
||||
@@ -148,7 +150,7 @@ class FlattenException
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setHeaders(array $headers): self
|
||||
public function setHeaders(array $headers): static
|
||||
{
|
||||
$this->headers = $headers;
|
||||
|
||||
@@ -163,9 +165,9 @@ class FlattenException
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setClass(string $class): self
|
||||
public function setClass(string $class): static
|
||||
{
|
||||
$this->class = false !== strpos($class, "@anonymous\0") ? (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous' : $class;
|
||||
$this->class = str_contains($class, "@anonymous\0") ? (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous' : $class;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -178,7 +180,7 @@ class FlattenException
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setFile(string $file): self
|
||||
public function setFile(string $file): static
|
||||
{
|
||||
$this->file = $file;
|
||||
|
||||
@@ -193,7 +195,7 @@ class FlattenException
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setLine(int $line): self
|
||||
public function setLine(int $line): static
|
||||
{
|
||||
$this->line = $line;
|
||||
|
||||
@@ -208,7 +210,7 @@ class FlattenException
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setStatusText(string $statusText): self
|
||||
public function setStatusText(string $statusText): static
|
||||
{
|
||||
$this->statusText = $statusText;
|
||||
|
||||
@@ -223,12 +225,10 @@ class FlattenException
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setMessage(string $message): self
|
||||
public function setMessage(string $message): static
|
||||
{
|
||||
if (false !== strpos($message, "@anonymous\0")) {
|
||||
$message = preg_replace_callback('/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', function ($m) {
|
||||
return class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0];
|
||||
}, $message);
|
||||
if (str_contains($message, "@anonymous\0")) {
|
||||
$message = preg_replace_callback('/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', fn ($m) => class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0], $message);
|
||||
}
|
||||
|
||||
$this->message = $message;
|
||||
@@ -239,17 +239,15 @@ class FlattenException
|
||||
/**
|
||||
* @return int|string int most of the time (might be a string with PDOException)
|
||||
*/
|
||||
public function getCode()
|
||||
public function getCode(): int|string
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|string $code
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setCode($code): self
|
||||
public function setCode(int|string $code): static
|
||||
{
|
||||
$this->code = $code;
|
||||
|
||||
@@ -264,7 +262,7 @@ class FlattenException
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setPrevious(?self $previous): self
|
||||
public function setPrevious(?self $previous): static
|
||||
{
|
||||
$this->previous = $previous;
|
||||
|
||||
@@ -293,7 +291,7 @@ class FlattenException
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setTraceFromThrowable(\Throwable $throwable): self
|
||||
public function setTraceFromThrowable(\Throwable $throwable): static
|
||||
{
|
||||
$this->traceAsString = $throwable->getTraceAsString();
|
||||
|
||||
@@ -303,7 +301,7 @@ class FlattenException
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setTrace(array $trace, ?string $file, ?int $line): self
|
||||
public function setTrace(array $trace, ?string $file, ?int $line): static
|
||||
{
|
||||
$this->trace = [];
|
||||
$this->trace[] = [
|
||||
@@ -340,6 +338,21 @@ class FlattenException
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDataRepresentation(): ?Data
|
||||
{
|
||||
return $this->dataRepresentation ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setDataRepresentation(Data $data): static
|
||||
{
|
||||
$this->dataRepresentation = $data;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function flattenArgs(array $args, int $level = 0, int &$count = 0): array
|
||||
{
|
||||
$result = [];
|
||||
@@ -350,7 +363,7 @@ class FlattenException
|
||||
if ($value instanceof \__PHP_Incomplete_Class) {
|
||||
$result[$key] = ['incomplete-object', $this->getClassNameFromIncomplete($value)];
|
||||
} elseif (\is_object($value)) {
|
||||
$result[$key] = ['object', \get_class($value)];
|
||||
$result[$key] = ['object', get_debug_type($value)];
|
||||
} elseif (\is_array($value)) {
|
||||
if ($level > 10) {
|
||||
$result[$key] = ['array', '*DEEP NESTED ARRAY*'];
|
||||
@@ -390,7 +403,7 @@ class FlattenException
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setAsString(?string $asString): self
|
||||
public function setAsString(?string $asString): static
|
||||
{
|
||||
$this->asString = $asString;
|
||||
|
||||
|
||||
@@ -20,10 +20,10 @@ class SilencedErrorContext implements \JsonSerializable
|
||||
{
|
||||
public $count = 1;
|
||||
|
||||
private $severity;
|
||||
private $file;
|
||||
private $line;
|
||||
private $trace;
|
||||
private int $severity;
|
||||
private string $file;
|
||||
private int $line;
|
||||
private array $trace;
|
||||
|
||||
public function __construct(int $severity, string $file, int $line, array $trace = [], int $count = 1)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user