You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
651 B
30 lines
651 B
<?php |
|
|
|
namespace App\Http\Middleware; |
|
|
|
use App\Services\AuditLogService; |
|
use App\Support\ApiActor; |
|
use Closure; |
|
use Illuminate\Http\Request; |
|
use Symfony\Component\HttpFoundation\Response; |
|
|
|
class ApiAuditMiddleware |
|
{ |
|
public function __construct( |
|
private readonly AuditLogService $audit |
|
) { |
|
} |
|
|
|
public function handle(Request $request, Closure $next): Response |
|
{ |
|
$response = $next($request); |
|
|
|
$actor = $request->attributes->get('api_actor'); |
|
|
|
if ($actor instanceof ApiActor) { |
|
$this->audit->logApi($request, $actor, $response->getStatusCode()); |
|
} |
|
|
|
return $response; |
|
} |
|
}
|
|
|