|
1 | 1 | <?php |
2 | 2 |
|
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 | + } |
6 | 30 | } |
7 | 31 |
|
| 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 | + |
8 | 41 | $rth_class = '\Composer\Autoload\ClassLoader'; |
9 | 42 |
|
10 | 43 | if (!class_exists($rth_class, false)) { |
|
0 commit comments