Skip to content

Commit fba6758

Browse files
authored
[4.1] Log deprecated only when explicitly requested (#31143)
* log:logDeprecated * use new log method * new log method, improve callStack lookup * phpcs * phpcs * Check deprecation logging on boot * trigger_error everywhere * use namespaced classes
1 parent a4854f3 commit fba6758

File tree

16 files changed

+130
-105
lines changed

16 files changed

+130
-105
lines changed

administrator/includes/framework.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@
7777

7878
define('JDEBUG', $config->debug);
7979

80+
// Check deprecation logging
81+
if (empty($config->log_deprecated))
82+
{
83+
// Reset handler for E_USER_DEPRECATED
84+
set_error_handler(null, E_USER_DEPRECATED);
85+
}
86+
else
87+
{
88+
// Make sure handler for E_USER_DEPRECATED is registered
89+
set_error_handler(['Joomla\CMS\Exception\ExceptionHandler', 'handleUserDeprecatedErrors'], E_USER_DEPRECATED);
90+
}
91+
8092
if (JDEBUG || $config->error_reporting === 'maximum')
8193
{
8294
// Set new Exception handler with debug enabled

api/includes/framework.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@
8282

8383
define('JDEBUG', $config->debug);
8484

85+
// Check deprecation logging
86+
if (empty($config->log_deprecated))
87+
{
88+
// Reset handler for E_USER_DEPRECATED
89+
set_error_handler(null, E_USER_DEPRECATED);
90+
}
91+
else
92+
{
93+
// Make sure handler for E_USER_DEPRECATED is registered
94+
set_error_handler(['Joomla\CMS\Exception\ExceptionHandler', 'handleUserDeprecatedErrors'], E_USER_DEPRECATED);
95+
}
96+
8597
if (JDEBUG || $config->error_reporting === 'maximum')
8698
{
8799
// Set new Exception handler with debug enabled

includes/framework.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@
8080
define('JDEBUG', $config->debug);
8181
}
8282

83+
// Check deprecation logging
84+
if (empty($config->log_deprecated))
85+
{
86+
// Reset handler for E_USER_DEPRECATED
87+
set_error_handler(null, E_USER_DEPRECATED);
88+
}
89+
else
90+
{
91+
// Make sure handler for E_USER_DEPRECATED is registered
92+
set_error_handler(['Joomla\CMS\Exception\ExceptionHandler', 'handleUserDeprecatedErrors'], E_USER_DEPRECATED);
93+
}
94+
8395
if (JDEBUG || $config->error_reporting === 'maximum')
8496
{
8597
// Set new Exception handler with debug enabled

libraries/bootstrap.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ class_exists('\\Joomla\\CMS\\Autoload\\ClassLoader');
5757
\Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer::setTemplate(__DIR__ . '/../templates/system/fatal.php');
5858

5959
// Register the error handler which processes E_USER_DEPRECATED errors
60-
set_error_handler(['Joomla\CMS\Exception\ExceptionHandler', 'handleUserDeprecatedErrors'], E_USER_DEPRECATED);
60+
if (error_reporting() & E_USER_DEPRECATED)
61+
{
62+
set_error_handler(['Joomla\CMS\Exception\ExceptionHandler', 'handleUserDeprecatedErrors'], E_USER_DEPRECATED);
63+
}
6164

6265
// Suppress phar stream wrapper for non .phar files
6366
$behavior = new \TYPO3\PharStreamWrapper\Behavior;

libraries/src/Document/Renderer/Html/MessageRenderer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ public function render($name, $params = array(), $content = null)
5353

5454
if (\function_exists('renderMessage'))
5555
{
56-
Log::add('renderMessage() is deprecated. Override system message rendering with layouts instead.', Log::WARNING, 'deprecated');
56+
@trigger_error(
57+
'renderMessage() is deprecated. Override system message rendering with layouts instead.',
58+
E_USER_DEPRECATED
59+
);
5760

5861
return renderMessage($msgList);
5962
}

libraries/src/Exception/ExceptionHandler.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@ public static function handleUserDeprecatedErrors(int $errorNumber, string $erro
3939
// We only want to handle user deprecation messages, these will be triggered in code
4040
if ($errorNumber === E_USER_DEPRECATED)
4141
{
42-
Log::add(
43-
$errorMessage,
44-
Log::WARNING,
45-
'deprecated'
46-
);
42+
try
43+
{
44+
Log::add($errorMessage, Log::WARNING, 'deprecated');
45+
}
46+
catch (\Exception $e)
47+
{
48+
// Silence
49+
}
4750

4851
// If debug mode is enabled, we want to let PHP continue to handle the error; otherwise, we can bail early
4952
if (\defined('JDEBUG') && JDEBUG)

libraries/src/HTML/HTMLHelper.php

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,10 @@ protected static function extract($key)
8686

8787
if (\count($parts) === 3)
8888
{
89-
try
90-
{
91-
Log::add(
92-
'Support for a three segment service key is deprecated and will be removed in Joomla 5.0, use the service registry instead',
93-
Log::WARNING,
94-
'deprecated'
95-
);
96-
}
97-
catch (\RuntimeException $exception)
98-
{
99-
// Informational message only, continue on
100-
}
89+
@trigger_error(
90+
'Support for a three segment service key is deprecated and will be removed in Joomla 5.0, use the service registry instead',
91+
E_USER_DEPRECATED
92+
);
10193
}
10294

10395
$prefix = \count($parts) === 3 ? array_shift($parts) : 'JHtml';
@@ -207,18 +199,10 @@ final public static function _(string $key, ...$methodArgs)
207199
*/
208200
public static function register($key, callable $function)
209201
{
210-
try
211-
{
212-
Log::add(
213-
'Support for registering functions is deprecated and will be removed in Joomla 5.0, use the service registry instead',
214-
Log::WARNING,
215-
'deprecated'
216-
);
217-
}
218-
catch (\RuntimeException $exception)
219-
{
220-
// Informational message only, continue on
221-
}
202+
@trigger_error(
203+
'Support for registering functions is deprecated and will be removed in Joomla 5.0, use the service registry instead',
204+
E_USER_DEPRECATED
205+
);
222206

223207
list($key) = static::extract($key);
224208

@@ -239,18 +223,10 @@ public static function register($key, callable $function)
239223
*/
240224
public static function unregister($key)
241225
{
242-
try
243-
{
244-
Log::add(
245-
'Support for registering functions is deprecated and will be removed in Joomla 5.0, use the service registry instead',
246-
Log::WARNING,
247-
'deprecated'
248-
);
249-
}
250-
catch (\RuntimeException $exception)
251-
{
252-
// Informational message only, continue on
253-
}
226+
@trigger_error(
227+
'Support for registering functions is deprecated and will be removed in Joomla 5.0, use the service registry instead',
228+
E_USER_DEPRECATED
229+
);
254230

255231
list($key) = static::extract($key);
256232

@@ -1220,18 +1196,10 @@ public static function calendar($value, $name, $id, $format = '%Y-%m-%d', $attri
12201196
*/
12211197
public static function addIncludePath($path = '')
12221198
{
1223-
try
1224-
{
1225-
Log::add(
1226-
'Support for registering lookup paths is deprecated and will be removed in Joomla 5.0, use the service registry instead',
1227-
Log::WARNING,
1228-
'deprecated'
1229-
);
1230-
}
1231-
catch (\RuntimeException $exception)
1232-
{
1233-
// Informational message only, continue on
1234-
}
1199+
@trigger_error(
1200+
'Support for registering lookup paths is deprecated and will be removed in Joomla 5.0, use the service registry instead',
1201+
E_USER_DEPRECATED
1202+
);
12351203

12361204
// Loop through the path directories
12371205
foreach ((array) $path as $dir)

libraries/src/Language/Text.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,15 +350,14 @@ public static function script($string = null, $jsSafe = false, $interpretBackSla
350350
{
351351
if ($string === null)
352352
{
353-
Log::add(
353+
@trigger_error(
354354
sprintf(
355355
'As of 3.7.0, passing a null value for the first argument of %1$s() is deprecated and will not be supported in 4.0.'
356356
. ' Use the %2$s::getScriptStrings() method to get the strings from the JavaScript language store instead.',
357357
__METHOD__,
358358
__CLASS__
359359
),
360-
Log::WARNING,
361-
'deprecated'
360+
E_USER_DEPRECATED
362361
);
363362
}
364363

libraries/src/Log/Log.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
\defined('JPATH_PLATFORM') or die;
1212

13+
use Joomla\CMS\Factory;
14+
1315
/**
1416
* Joomla! Log Class
1517
*

libraries/src/MVC/View/HtmlView.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ public function __construct($config = array())
112112
// Set the charset (used by the variable escaping functions)
113113
if (\array_key_exists('charset', $config))
114114
{
115-
Log::add('Setting a custom charset for escaping is deprecated. Override \JViewLegacy::escape() instead.', Log::WARNING, 'deprecated');
115+
@trigger_error(
116+
'Setting a custom charset for escaping is deprecated. Override \JViewLegacy::escape() instead.',
117+
E_USER_DEPRECATED
118+
);
116119
$this->_charset = $config['charset'];
117120
}
118121

0 commit comments

Comments
 (0)