Skip to content

Commit 6fa0f70

Browse files
committed
feat: improve deprecated vendor-no-composer message and add new function rth_trigger_error_once($message, $type, $frequency)
1 parent 528658c commit 6fa0f70

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

src/Templates/autoload.php.tmpl

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,43 @@
11
<?php
22

3-
if (strpos(__DIR__, 'vendor-no-composer') !== false) {
4-
/** E_USER_DEPRECATED does not work */
5-
trigger_error('Using file vendor-no-composer/autoload.php is deprecated. Use vendor-mmlc/autoload.php instead.', E_USER_NOTICE);
3+
// Triggers an error only every $frequency seconds.
4+
if (!function_exists('rth_trigger_error_once')) {
5+
function rth_trigger_error_once($message, $type, $frequency)
6+
{
7+
$cache = [];
8+
$cacheFilePath = DIR_FS_DOCUMENT_ROOT . '/log/mmlc_log_cache.json';
9+
10+
// Load cache
11+
if (file_exists($cacheFilePath)) {
12+
$cacheData = file_get_contents($cacheFilePath);
13+
$cache = json_decode($cacheData, true);
14+
}
15+
16+
// Check time;
17+
$messageId = md5($message);
18+
$currentTime = time();
19+
20+
if (isset($cache[$messageId]) && ($currentTime - $cache[$messageId]) < $frequency) {
21+
return false;
22+
}
23+
24+
trigger_error($message, $type);
25+
26+
// Update cache
27+
$cache[$messageId] = $currentTime;
28+
file_put_contents($cacheFilePath, json_encode($cache));
29+
}
630
}
731

32+
//if (strpos(__DIR__, 'vendor-no-composer') !== false) {
33+
/** E_USER_DEPRECATED does not work */
34+
rth_trigger_error_once(
35+
'The file vendor-no-composer/autoload.php is deprecated. Please use vendor-mmlc/autoload.php instead. This warning appears because some module developers still include the outdated file vendor-no-composer/autoload.php. While this is not yet an issue, it may cause problems in future versions of MMLC, when vendor-no-composer/autoload.php will be removed. Note: This message is logged only once every 3600 seconds.',
36+
E_USER_NOTICE,
37+
3600
38+
);
39+
//}
40+
841
$rth_class = '\Composer\Autoload\ClassLoader';
942

1043
if (!class_exists($rth_class, false)) {

0 commit comments

Comments
 (0)