36 lines
1 KiB
PHP
36 lines
1 KiB
PHP
<?php
|
|
|
|
namespace ctiso\Filter;
|
|
use ctiso\Role\UserInterface,
|
|
ctiso\HttpRequest;
|
|
|
|
/* Переделать формат Логов на список json */
|
|
class ActionLogger
|
|
{
|
|
public $before = array();
|
|
public $file;
|
|
public $user;
|
|
public $action;
|
|
public $processor;
|
|
|
|
function __construct($processor/*: Filter*/, $logPath, $user/*: UserInterface*/) {
|
|
$this->processor = $processor;
|
|
$this->user = $user;
|
|
|
|
$file = fopen($logPath, "a");
|
|
if (is_resource($file)) {
|
|
$this->file = $file;
|
|
} else {
|
|
throw new \Exception('Ошибка открытия файла ' . $logPath);
|
|
}
|
|
}
|
|
|
|
function execute(HttpRequest $request) {
|
|
$action = $request->getAction();
|
|
if(in_array($action, $this->before)) {
|
|
$message = ["time" => date("r", time()), "query" => array_merge($_POST, $_GET), "user" => $this->user->getName()];
|
|
fwrite($this->file, json_encode($message) . "\n");
|
|
}
|
|
return $this->processor->execute($request);
|
|
}
|
|
}
|