Skip to content

Commit 88ad555

Browse files
fix: change path to actual routes
1 parent 1f58c44 commit 88ad555

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

app/Audit/AuditEventListener.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424
*/
2525
class AuditEventListener
2626
{
27+
private const ROUTE_METHOD_SEPARATOR = '|';
2728

2829
public function onFlush(OnFlushEventArgs $eventArgs): void
2930
{
30-
if (app()->environment('testing')){
31+
if (app()->environment('testing')) {
3132
return;
3233
}
3334
$em = $eventArgs->getObjectManager();
@@ -68,7 +69,7 @@ public function onFlush(OnFlushEventArgs $eventArgs): void
6869
/**
6970
* Get the appropriate audit strategy based on environment configuration
7071
*/
71-
private function getAuditStrategy($em)
72+
private function getAuditStrategy($em): ?IAuditStrategy
7273
{
7374
// Check if OTLP audit is enabled
7475
if (config('opentelemetry.enabled', false)) {
@@ -99,9 +100,9 @@ private function buildAuditContext(): AuditContext
99100

100101
$req = request();
101102

102-
$route = Route::getRoutes()->match(request());
103-
$method = isset($route->methods[0]) ? $route->methods[0] : null;
104-
$rawRoute = $method."|".$route->uri;
103+
$route = Route::getRoutes()->match($req);
104+
$method = $route->methods[0] ?? 'UNKNOWN';
105+
$rawRoute = $method . self::ROUTE_METHOD_SEPARATOR . $route->uri;
105106

106107
return new AuditContext(
107108
userId: $member?->getId(),

app/Audit/AuditLogFormatterFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private function getFormatterByContext(object $subject, string $event_type, Audi
108108

109109
private function matchesStrategy(array $strategy, AuditContext $ctx): bool
110110
{
111-
if (isset($strategy['route']) && !$this->routeMatches($strategy['route'], $ctx->route)) {
111+
if (isset($strategy['route']) && !$this->routeMatches($strategy['route'], $ctx->rawRoute)) {
112112
return false;
113113
}
114114

0 commit comments

Comments
 (0)