package and depencies
This commit is contained in:
@@ -24,54 +24,25 @@ 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;
|
||||
|
||||
/** @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 +55,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 +67,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());
|
||||
|
||||
@@ -133,7 +102,7 @@ class FlattenException
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setStatusCode(int $code): self
|
||||
public function setStatusCode(int $code): static
|
||||
{
|
||||
$this->statusCode = $code;
|
||||
|
||||
@@ -148,7 +117,7 @@ class FlattenException
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setHeaders(array $headers): self
|
||||
public function setHeaders(array $headers): static
|
||||
{
|
||||
$this->headers = $headers;
|
||||
|
||||
@@ -163,9 +132,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 +147,7 @@ class FlattenException
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setFile(string $file): self
|
||||
public function setFile(string $file): static
|
||||
{
|
||||
$this->file = $file;
|
||||
|
||||
@@ -193,7 +162,7 @@ class FlattenException
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setLine(int $line): self
|
||||
public function setLine(int $line): static
|
||||
{
|
||||
$this->line = $line;
|
||||
|
||||
@@ -208,7 +177,7 @@ class FlattenException
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setStatusText(string $statusText): self
|
||||
public function setStatusText(string $statusText): static
|
||||
{
|
||||
$this->statusText = $statusText;
|
||||
|
||||
@@ -223,9 +192,9 @@ class FlattenException
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setMessage(string $message): self
|
||||
public function setMessage(string $message): static
|
||||
{
|
||||
if (false !== strpos($message, "@anonymous\0")) {
|
||||
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]++/', function ($m) {
|
||||
return class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0];
|
||||
}, $message);
|
||||
@@ -239,17 +208,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 +231,7 @@ class FlattenException
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setPrevious(?self $previous): self
|
||||
public function setPrevious(?self $previous): static
|
||||
{
|
||||
$this->previous = $previous;
|
||||
|
||||
@@ -293,7 +260,7 @@ class FlattenException
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setTraceFromThrowable(\Throwable $throwable): self
|
||||
public function setTraceFromThrowable(\Throwable $throwable): static
|
||||
{
|
||||
$this->traceAsString = $throwable->getTraceAsString();
|
||||
|
||||
@@ -303,7 +270,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[] = [
|
||||
@@ -350,7 +317,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 +357,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