mirror of
https://github.com/symfony/error-handler.git
synced 2026-03-24 00:02:09 +01:00
Add union types
This commit is contained in:
@@ -162,7 +162,7 @@ class ErrorHandler
|
||||
*
|
||||
* @throws \ErrorException When $function(...$arguments) triggers a PHP error
|
||||
*/
|
||||
public static function call(callable $function, ...$arguments)
|
||||
public static function call(callable $function, mixed ...$arguments)
|
||||
{
|
||||
set_error_handler(static function (int $type, string $message, string $file, int $line) {
|
||||
if (__FILE__ === $file) {
|
||||
@@ -202,10 +202,10 @@ class ErrorHandler
|
||||
* Sets a logger to non assigned errors levels.
|
||||
*
|
||||
* @param LoggerInterface $logger A PSR-3 logger to put as default for the given levels
|
||||
* @param array|int $levels An array map of E_* to LogLevel::* or an integer bit field of E_* constants
|
||||
* @param array|int|null $levels An array map of E_* to LogLevel::* or an integer bit field of E_* constants
|
||||
* @param bool $replace Whether to replace or not any existing logger
|
||||
*/
|
||||
public function setDefaultLogger(LoggerInterface $logger, $levels = \E_ALL, bool $replace = false): void
|
||||
public function setDefaultLogger(LoggerInterface $logger, array|int|null $levels = \E_ALL, bool $replace = false): void
|
||||
{
|
||||
$loggers = [];
|
||||
|
||||
|
||||
@@ -43,20 +43,11 @@ class HtmlErrorRenderer implements ErrorRendererInterface
|
||||
private static $template = 'views/error.html.php';
|
||||
|
||||
/**
|
||||
* @param bool|callable $debug The debugging mode as a boolean or a callable that should return it
|
||||
* @param string|FileLinkFormatter|null $fileLinkFormat
|
||||
* @param bool|callable $outputBuffer The output buffer as a string or a callable that should return it
|
||||
* @param bool|callable $debug The debugging mode as a boolean or a callable that should return it
|
||||
* @param string|callable $outputBuffer The output buffer as a string or a callable that should return it
|
||||
*/
|
||||
public function __construct($debug = false, string $charset = null, $fileLinkFormat = null, string $projectDir = null, $outputBuffer = '', LoggerInterface $logger = null)
|
||||
public function __construct(bool|callable $debug = false, string $charset = null, string|FileLinkFormatter|null $fileLinkFormat = null, string $projectDir = null, string|callable $outputBuffer = '', LoggerInterface $logger = null)
|
||||
{
|
||||
if (!\is_bool($debug) && !\is_callable($debug)) {
|
||||
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be a boolean or a callable, "%s" given.', __METHOD__, get_debug_type($debug)));
|
||||
}
|
||||
|
||||
if (!\is_string($outputBuffer) && !\is_callable($outputBuffer)) {
|
||||
throw new \TypeError(sprintf('Argument 5 passed to "%s()" must be a string or a callable, "%s" given.', __METHOD__, get_debug_type($outputBuffer)));
|
||||
}
|
||||
|
||||
$this->debug = $debug;
|
||||
$this->charset = $charset ?: (ini_get('default_charset') ?: 'UTF-8');
|
||||
$this->fileLinkFormat = $fileLinkFormat ?: (ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format'));
|
||||
|
||||
@@ -34,16 +34,8 @@ class SerializerErrorRenderer implements ErrorRendererInterface
|
||||
* formats not supported by Request::getMimeTypes() should be given as mime types
|
||||
* @param bool|callable $debug The debugging mode as a boolean or a callable that should return it
|
||||
*/
|
||||
public function __construct(SerializerInterface $serializer, $format, ErrorRendererInterface $fallbackErrorRenderer = null, $debug = false)
|
||||
public function __construct(SerializerInterface $serializer, string|callable $format, ErrorRendererInterface $fallbackErrorRenderer = null, bool|callable $debug = false)
|
||||
{
|
||||
if (!\is_string($format) && !\is_callable($format)) {
|
||||
throw new \TypeError(sprintf('Argument 2 passed to "%s()" must be a string or a callable, "%s" given.', __METHOD__, get_debug_type($format)));
|
||||
}
|
||||
|
||||
if (!\is_bool($debug) && !\is_callable($debug)) {
|
||||
throw new \TypeError(sprintf('Argument 4 passed to "%s()" must be a boolean or a callable, "%s" given.', __METHOD__, get_debug_type($debug)));
|
||||
}
|
||||
|
||||
$this->serializer = $serializer;
|
||||
$this->format = $format;
|
||||
$this->fallbackErrorRenderer = $fallbackErrorRenderer ?? new HtmlErrorRenderer();
|
||||
|
||||
@@ -63,7 +63,7 @@ class FlattenException
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function create(\Exception $exception, $statusCode = null, array $headers = []): self
|
||||
public static function create(\Exception $exception, int $statusCode = null, array $headers = []): self
|
||||
{
|
||||
return static::createFromThrowable($exception, $statusCode, $headers);
|
||||
}
|
||||
@@ -131,11 +131,9 @@ class FlattenException
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $code
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setStatusCode($code): self
|
||||
public function setStatusCode(int $code): self
|
||||
{
|
||||
$this->statusCode = $code;
|
||||
|
||||
@@ -163,11 +161,9 @@ class FlattenException
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setClass($class): self
|
||||
public function setClass(string $class): self
|
||||
{
|
||||
$this->class = false !== strpos($class, "@anonymous\0") ? (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous' : $class;
|
||||
|
||||
@@ -180,11 +176,9 @@ class FlattenException
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setFile($file): self
|
||||
public function setFile(string $file): self
|
||||
{
|
||||
$this->file = $file;
|
||||
|
||||
@@ -197,11 +191,9 @@ class FlattenException
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $line
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setLine($line): self
|
||||
public function setLine(int $line): self
|
||||
{
|
||||
$this->line = $line;
|
||||
|
||||
@@ -226,11 +218,9 @@ class FlattenException
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setMessage($message): self
|
||||
public function setMessage(string $message): self
|
||||
{
|
||||
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) {
|
||||
@@ -252,11 +242,9 @@ class FlattenException
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|string $code
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setCode($code): self
|
||||
public function setCode(int|string $code): self
|
||||
{
|
||||
$this->code = $code;
|
||||
|
||||
@@ -308,13 +296,10 @@ class FlattenException
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $trace
|
||||
* @param string|null $file
|
||||
* @param int|null $line
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTrace($trace, $file, $line): self
|
||||
public function setTrace(array $trace, ?string $file, ?int $line): self
|
||||
{
|
||||
$this->trace = [];
|
||||
$this->trace[] = [
|
||||
|
||||
@@ -18,10 +18,7 @@ use Symfony\Component\ErrorHandler\Exception\SilencedErrorContext;
|
||||
*/
|
||||
class ThrowableUtils
|
||||
{
|
||||
/**
|
||||
* @param SilencedErrorContext|\Throwable
|
||||
*/
|
||||
public static function getSeverity($throwable): int
|
||||
public static function getSeverity(SilencedErrorContext|\Throwable $throwable): int
|
||||
{
|
||||
if ($throwable instanceof \ErrorException || $throwable instanceof SilencedErrorContext) {
|
||||
return $throwable->getSeverity();
|
||||
|
||||
Reference in New Issue
Block a user