debug
This commit is contained in:
@@ -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'])) {
|
||||
|
||||
Reference in New Issue
Block a user