Skip to content

Commit 8f13fc0

Browse files
ycerutofabpot
authored andcommitted
[ErrorHandler] Decouple from ErrorRenderer component
1 parent a7852c0 commit 8f13fc0

File tree

9 files changed

+18
-381
lines changed

9 files changed

+18
-381
lines changed

src/Symfony/Component/Debug/ExceptionHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Symfony\Component\Debug\Exception\OutOfMemoryException;
1616
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
1717

18-
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', ExceptionHandler::class, \Symfony\Component\ErrorHandler\ExceptionHandler::class), E_USER_DEPRECATED);
18+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', ExceptionHandler::class, \Symfony\Component\ErrorHandler\ErrorHandler::class), E_USER_DEPRECATED);
1919

2020
/**
2121
* ExceptionHandler converts an exception to a Response object.
@@ -31,7 +31,7 @@
3131
*
3232
* @final since Symfony 4.3
3333
*
34-
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\ExceptionHandler instead.
34+
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\ErrorHandler instead.
3535
*/
3636
class ExceptionHandler
3737
{

src/Symfony/Component/ErrorHandler/Debug.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public static function enable($errorReportingLevel = E_ALL, $displayErrors = tru
4444

4545
if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) {
4646
ini_set('display_errors', 0);
47-
ExceptionHandler::register();
4847
} elseif ($displayErrors && (!filter_var(ini_get('log_errors'), FILTER_VALIDATE_BOOLEAN) || ini_get('error_log'))) {
4948
// CLI - display errors only if they're not already logged to STDERR
5049
ini_set('display_errors', 1);

src/Symfony/Component/ErrorHandler/ErrorHandler.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use Symfony\Component\ErrorHandler\FatalErrorHandler\FatalErrorHandlerInterface;
2222
use Symfony\Component\ErrorHandler\FatalErrorHandler\UndefinedFunctionFatalErrorHandler;
2323
use Symfony\Component\ErrorHandler\FatalErrorHandler\UndefinedMethodFatalErrorHandler;
24-
use Symfony\Component\ErrorRenderer\Exception\FlattenException;
2524

2625
/**
2726
* A generic ErrorHandler for the PHP engine.
@@ -414,7 +413,7 @@ public function handleError($type, $message, $file, $line)
414413
}
415414

416415
if (false !== strpos($message, "class@anonymous\0")) {
417-
$logMessage = $this->levels[$type].': '.(new FlattenException())->setMessage($message)->getMessage();
416+
$logMessage = $this->parseAnonymousClass($message);
418417
} else {
419418
$logMessage = $this->levels[$type].': '.$message;
420419
}
@@ -539,7 +538,7 @@ public function handleException($exception, array $error = null)
539538

540539
if (($this->loggedErrors & $type) || $exception instanceof FatalThrowableError) {
541540
if (false !== strpos($message = $exception->getMessage(), "class@anonymous\0")) {
542-
$message = (new FlattenException())->setMessage($message)->getMessage();
541+
$message = $this->parseAnonymousClass($message);
543542
}
544543
if ($exception instanceof FatalErrorException) {
545544
if ($exception instanceof FatalThrowableError) {
@@ -712,4 +711,15 @@ private function cleanTrace($backtrace, $type, $file, $line, $throw)
712711

713712
return $lightTrace;
714713
}
714+
715+
/**
716+
* Parse the error message by removing the anonymous class notation
717+
* and using the parent class instead if possible.
718+
*/
719+
private function parseAnonymousClass(string $message): string
720+
{
721+
return preg_replace_callback('/class@anonymous\x00.*?\.php0x?[0-9a-fA-F]++/', static function ($m) {
722+
return class_exists($m[0], false) ? get_parent_class($m[0]).'@anonymous' : $m[0];
723+
}, $message);
724+
}
715725
}

src/Symfony/Component/ErrorHandler/ExceptionHandler.php

Lines changed: 0 additions & 187 deletions
This file was deleted.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy