This commit is contained in:
2026-02-03 02:37:44 +01:00
parent ea5e25e6a8
commit b215ba3b60
4 changed files with 49 additions and 24 deletions

View File

@@ -10,6 +10,46 @@ if (!isset($GLOBALS['page_styles'])) {
$GLOBALS['page_styles'] = [];
}
function debug_log_write(string $name, $payload, array $options = []): bool
{
$dir = (string)($options['dir'] ?? (dirname(__DIR__) . '/debug'));
if ($dir === '') {
return false;
}
if (!is_dir($dir)) {
@mkdir($dir, 0777, true);
@chmod($dir, 0777);
}
$fileName = (string)($options['filename'] ?? '');
if ($fileName === '') {
$safeName = preg_replace('/[^a-zA-Z0-9_\.\-]/', '_', $name) ?: 'debug';
$fileName = $safeName . '.log';
} else {
$fileName = basename($fileName);
}
$asJson = $options['json'] ?? (is_array($payload) || is_object($payload));
if ($asJson) {
$line = json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
} else {
$line = is_string($payload) ? $payload : (string)$payload;
}
if (($options['newline'] ?? true) && $line !== '' && substr($line, -1) !== "\n") {
$line .= "\n";
}
$path = rtrim($dir, '/\\') . '/' . $fileName;
$flags = ($options['append'] ?? false) ? FILE_APPEND : 0;
$result = @file_put_contents($path, $line, $flags | LOCK_EX);
if ($result === false) {
return false;
}
@chmod($path, 0666);
return true;
}
function helper_asset_version(): ?string
{
if (isset($GLOBALS['layoutContext']['asset_version'])) {