From 09ff052c1fd76f56fc3866cb74aeb6abc6ebd233 Mon Sep 17 00:00:00 2001 From: Molkobain Date: Thu, 27 Jan 2022 11:40:19 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B04072=20-=20Add=20method=20to=20deprecate?= =?UTF-8?q?=20PHP=20endpoints?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/log.class.inc.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/core/log.class.inc.php b/core/log.class.inc.php index d780d032e..09eb0380b 100644 --- a/core/log.class.inc.php +++ b/core/log.class.inc.php @@ -1004,6 +1004,11 @@ class DeadLockLog extends LogAPI class DeprecatedCallsLog extends LogAPI { public const ENUM_CHANNEL_PHP_METHOD = 'deprecated-php-method'; + /** + * @var string + * @since 3.1.0 + */ + public const ENUM_CHANNEL_PHP_ENDPOINT = 'deprecated-php-endpoint'; public const ENUM_CHANNEL_PHP_LIBMETHOD = 'deprecated-php-libmethod'; public const ENUM_CHANNEL_FILE = 'deprecated-file'; public const CHANNEL_DEFAULT = self::ENUM_CHANNEL_PHP_METHOD; @@ -1211,6 +1216,35 @@ class DeprecatedCallsLog extends LogAPI static::Warning($sMessage, self::ENUM_CHANNEL_PHP_METHOD); } + /** + * @param string|null $sAdditionalMessage + * @since 3.1.0 + */ + public static function NotifyDeprecatedPhpEndpoint(?string $sAdditionalMessage = null): void + { + try { + if (!static::IsLogLevelEnabled(self::LEVEL_WARNING, self::ENUM_CHANNEL_PHP_ENDPOINT)) { + return; + } + } + catch (ConfigException $e) { + return; + } + + $aStack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3); + $iStackDeprecatedMethodLevel = 0; // level 0 = current method, level 1 = method containing the `NotifyDeprecatedPhpMethod` call + $sDeprecatedUrl = $_SERVER['REQUEST_URI']; + $sCallerFile = $aStack[$iStackDeprecatedMethodLevel]['file']; + $sCallerLine = $aStack[$iStackDeprecatedMethodLevel]['line']; + $sMessage = "Call to endpoint {$sDeprecatedUrl} in {$sCallerFile}#L{$sCallerLine}"; + + if (!is_null($sAdditionalMessage)) { + $sMessage .= ' : '.$sAdditionalMessage; + } + + static::Warning($sMessage, self::ENUM_CHANNEL_PHP_ENDPOINT); + } + public static function Log($sLevel, $sMessage, $sChannel = null, $aContext = array()): void { if (true === utils::IsDevelopmentEnvironment()) {