🔧
This commit is contained in:
32
vendor/symfony/error-handler/ErrorHandler.php
vendored
32
vendor/symfony/error-handler/ErrorHandler.php
vendored
@@ -55,7 +55,6 @@ class ErrorHandler
|
||||
\E_USER_DEPRECATED => 'User Deprecated',
|
||||
\E_NOTICE => 'Notice',
|
||||
\E_USER_NOTICE => 'User Notice',
|
||||
\E_STRICT => 'Runtime Notice',
|
||||
\E_WARNING => 'Warning',
|
||||
\E_USER_WARNING => 'User Warning',
|
||||
\E_COMPILE_WARNING => 'Compile Warning',
|
||||
@@ -73,7 +72,6 @@ class ErrorHandler
|
||||
\E_USER_DEPRECATED => [null, LogLevel::INFO],
|
||||
\E_NOTICE => [null, LogLevel::WARNING],
|
||||
\E_USER_NOTICE => [null, LogLevel::WARNING],
|
||||
\E_STRICT => [null, LogLevel::WARNING],
|
||||
\E_WARNING => [null, LogLevel::WARNING],
|
||||
\E_USER_WARNING => [null, LogLevel::WARNING],
|
||||
\E_COMPILE_WARNING => [null, LogLevel::WARNING],
|
||||
@@ -108,7 +106,7 @@ class ErrorHandler
|
||||
/**
|
||||
* Registers the error handler.
|
||||
*/
|
||||
public static function register(self $handler = null, bool $replace = true): self
|
||||
public static function register(?self $handler = null, bool $replace = true): self
|
||||
{
|
||||
if (null === self::$reservedMemory) {
|
||||
self::$reservedMemory = str_repeat('x', 32768);
|
||||
@@ -179,8 +177,13 @@ class ErrorHandler
|
||||
}
|
||||
}
|
||||
|
||||
public function __construct(BufferingLogger $bootstrappingLogger = null, bool $debug = false)
|
||||
public function __construct(?BufferingLogger $bootstrappingLogger = null, bool $debug = false)
|
||||
{
|
||||
if (\PHP_VERSION_ID < 80400) {
|
||||
$this->levels[\E_STRICT] = 'Runtime Notice';
|
||||
$this->loggers[\E_STRICT] = [null, LogLevel::WARNING];
|
||||
}
|
||||
|
||||
if ($bootstrappingLogger) {
|
||||
$this->bootstrappingLogger = $bootstrappingLogger;
|
||||
$this->setDefaultLogger($bootstrappingLogger);
|
||||
@@ -432,7 +435,7 @@ class ErrorHandler
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (str_contains($message, '@anonymous')) {
|
||||
if (PHP_VERSION_ID < 80303 && str_contains($message, '@anonymous')) {
|
||||
$backtrace = debug_backtrace(false, 5);
|
||||
|
||||
for ($i = 1; isset($backtrace[$i]); ++$i) {
|
||||
@@ -440,8 +443,7 @@ class ErrorHandler
|
||||
&& ('trigger_error' === $backtrace[$i]['function'] || 'user_error' === $backtrace[$i]['function'])
|
||||
) {
|
||||
if ($backtrace[$i]['args'][0] !== $message) {
|
||||
$message = $this->parseAnonymousClass($backtrace[$i]['args'][0]);
|
||||
$logMessage = $this->levels[$type].': '.$message;
|
||||
$message = $backtrace[$i]['args'][0];
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -449,6 +451,11 @@ class ErrorHandler
|
||||
}
|
||||
}
|
||||
|
||||
if (false !== strpos($message, "@anonymous\0")) {
|
||||
$message = $this->parseAnonymousClass($message);
|
||||
$logMessage = $this->levels[$type].': '.$message;
|
||||
}
|
||||
|
||||
$errorAsException = new \ErrorException($logMessage, 0, $type, $file, $line);
|
||||
|
||||
if ($throw || $this->tracedErrors & $type) {
|
||||
@@ -559,7 +566,7 @@ class ErrorHandler
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public static function handleFatalError(array $error = null): void
|
||||
public static function handleFatalError(?array $error = null): void
|
||||
{
|
||||
if (null === self::$reservedMemory) {
|
||||
return;
|
||||
@@ -591,6 +598,10 @@ class ErrorHandler
|
||||
set_exception_handler($h);
|
||||
}
|
||||
if (!$handler) {
|
||||
if (null === $error && $exitCode = self::$exitCode) {
|
||||
register_shutdown_function('register_shutdown_function', function () use ($exitCode) { exit($exitCode); });
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
if ($handler !== $h) {
|
||||
@@ -626,8 +637,7 @@ class ErrorHandler
|
||||
// Ignore this re-throw
|
||||
}
|
||||
|
||||
if ($exit && self::$exitCode) {
|
||||
$exitCode = self::$exitCode;
|
||||
if ($exit && $exitCode = self::$exitCode) {
|
||||
register_shutdown_function('register_shutdown_function', function () use ($exitCode) { exit($exitCode); });
|
||||
}
|
||||
}
|
||||
@@ -732,6 +742,6 @@ class ErrorHandler
|
||||
*/
|
||||
private function parseAnonymousClass(string $message): string
|
||||
{
|
||||
return preg_replace_callback('/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', static fn ($m) => class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0], $message);
|
||||
return preg_replace_callback('/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)?[0-9a-fA-F]++/', static fn ($m) => class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0], $message);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user