From aaba7c1a052d7708634dc31ab064470c5e4e5be8 Mon Sep 17 00:00:00 2001 From: Najdanovic Ivan Date: Mon, 17 Oct 2022 11:55:31 +0200 Subject: [PATCH] Exceptions - Log Deprecations --- app/Config/Exceptions.php | 13 +++++++++++++ system/Debug/Exceptions.php | 14 ++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/app/Config/Exceptions.php b/app/Config/Exceptions.php index 7cbc78a88a3a..0000d315bdcb 100644 --- a/app/Config/Exceptions.php +++ b/app/Config/Exceptions.php @@ -33,6 +33,19 @@ class Exceptions extends BaseConfig */ public $ignoreCodes = [404]; + /** + * -------------------------------------------------------------------------- + * DO NOT FAIL ON DEPRECATIONS + * -------------------------------------------------------------------------- + * By default deprecation errors will be thrown as exception stopping + * the framework from further code execution. With this parameter set to + * true the deprecations will not throw exception but instead will be written + * to the log with warning level. + * + * @var bool + */ + public $failOnDeprecated = true; + /** * -------------------------------------------------------------------------- * Error Views Path diff --git a/system/Debug/Exceptions.php b/system/Debug/Exceptions.php index 437a47268706..33de09a8f6b4 100644 --- a/system/Debug/Exceptions.php +++ b/system/Debug/Exceptions.php @@ -153,6 +153,20 @@ public function exceptionHandler(Throwable $exception) */ public function errorHandler(int $severity, string $message, ?string $file = null, ?int $line = null) { + if ($this->config->failOnDeprecated !== true && $severity === E_DEPRECATED) { + if ($this->config->log === true) { + $exception = new ErrorException($message, 0, $severity, $file, $line); + log_message('warning', "{message}\nin {exFile} on line {exLine}.\n{trace}", [ + 'message' => $exception->getMessage(), + 'exFile' => clean_path($exception->getFile()), // {file} refers to THIS file + 'exLine' => $exception->getLine(), // {line} refers to THIS line + 'trace' => self::renderBacktrace($exception->getTrace()), + ]); + } + + return; + } + if (! (error_reporting() & $severity)) { return; }