31 lines
906 B
PHP
31 lines
906 B
PHP
<?php
|
|
namespace Incoviba\Common\Implement\Log\Processor;
|
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
use Monolog\LogRecord;
|
|
use Monolog\Processor\ProcessorInterface;
|
|
|
|
class Request implements ProcessorInterface
|
|
{
|
|
public function __construct(protected ServerRequestInterface $request) {}
|
|
|
|
public function __invoke(LogRecord $record): LogRecord
|
|
{
|
|
$serverFilters = [
|
|
'HTTP_',
|
|
'QUERY_',
|
|
'REDIRECT_',
|
|
'REMOTE_',
|
|
'REQUEST_',
|
|
];
|
|
$serverParams = array_filter($this->request->getServerParams(),
|
|
fn($key) => count(array_filter($serverFilters, fn($prefix) => str_starts_with($key, $prefix))) > 0,
|
|
ARRAY_FILTER_USE_KEY);
|
|
$record->extra['request'] = [
|
|
'server' => $serverParams,
|
|
'headers' => $this->request->getHeaders(),
|
|
];
|
|
return $record;
|
|
}
|
|
}
|