init
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LayLink\Audit;
|
||||
|
||||
final class AuditLogger
|
||||
{
|
||||
public function __construct(private readonly string $path)
|
||||
{
|
||||
$dir = dirname($this->path);
|
||||
if (!is_dir($dir)) {
|
||||
mkdir($dir, 0775, true);
|
||||
}
|
||||
}
|
||||
|
||||
public function write(array $record): void
|
||||
{
|
||||
$record += [
|
||||
'end_time' => date(DATE_ATOM),
|
||||
];
|
||||
file_put_contents(
|
||||
$this->path,
|
||||
json_encode($record, JSON_UNESCAPED_SLASHES) . PHP_EOL,
|
||||
FILE_APPEND | LOCK_EX,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user