mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-06-25 22:58:41 +02:00
refactor: general code base refactor (#2950)
* refactor * fix: bug in previous refactor * chore: exclude phpcompat sniff due to bug in phpcompat * fix: do not leak absolute paths * refactor/fix: batch extensions checking, fix DOS issue
This commit is contained in:
parent
b042412416
commit
2bbce8ebef
45 changed files with 679 additions and 827 deletions
|
@ -64,7 +64,7 @@ function logBridgeError($bridgeName, $code)
|
|||
$cache->purgeCache(86400); // 24 hours
|
||||
|
||||
if ($report = $cache->loadData()) {
|
||||
$report = json_decode($report, true);
|
||||
$report = Json::decode($report);
|
||||
$report['time'] = time();
|
||||
$report['count']++;
|
||||
} else {
|
||||
|
@ -75,38 +75,7 @@ function logBridgeError($bridgeName, $code)
|
|||
];
|
||||
}
|
||||
|
||||
$cache->saveData(json_encode($report));
|
||||
$cache->saveData(Json::encode($report));
|
||||
|
||||
return $report['count'];
|
||||
}
|
||||
|
||||
function create_sane_stacktrace(\Throwable $e): array
|
||||
{
|
||||
$frames = array_reverse($e->getTrace());
|
||||
$frames[] = [
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
];
|
||||
$stackTrace = [];
|
||||
foreach ($frames as $i => $frame) {
|
||||
$file = $frame['file'] ?? '(no file)';
|
||||
$line = $frame['line'] ?? '(no line)';
|
||||
$stackTrace[] = sprintf(
|
||||
'#%s %s:%s',
|
||||
$i,
|
||||
trim_path_prefix($file),
|
||||
$line,
|
||||
);
|
||||
}
|
||||
return $stackTrace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim path prefix for privacy/security reasons
|
||||
*
|
||||
* Example: "/var/www/rss-bridge/index.php" => "index.php"
|
||||
*/
|
||||
function trim_path_prefix(string $filePath): string
|
||||
{
|
||||
return mb_substr($filePath, mb_strlen(dirname(__DIR__)) + 1);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue