|
|
|
@ -9,24 +9,22 @@ use App\Repository\VisitRepository; |
|
|
|
use Symfony\Component\EventDispatcher\Attribute\AsEventListener; |
|
|
|
use Symfony\Component\EventDispatcher\Attribute\AsEventListener; |
|
|
|
use Symfony\Component\HttpKernel\Event\RequestEvent; |
|
|
|
use Symfony\Component\HttpKernel\Event\RequestEvent; |
|
|
|
use Symfony\Component\HttpKernel\KernelEvents; |
|
|
|
use Symfony\Component\HttpKernel\KernelEvents; |
|
|
|
use Symfony\Bundle\SecurityBundle\Security; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[AsEventListener(event: KernelEvents::REQUEST, method: 'onKernelRequest', priority: 0)] |
|
|
|
#[AsEventListener(event: KernelEvents::REQUEST, method: 'onKernelRequest', priority: 0)] |
|
|
|
class VisitTrackingListener |
|
|
|
class VisitTrackingListener |
|
|
|
{ |
|
|
|
{ |
|
|
|
private const EXCLUDED_ROUTES = [ |
|
|
|
private const EXCLUDED_ROUTES = [ |
|
|
|
'/api/', |
|
|
|
|
|
|
|
'/_profiler', |
|
|
|
'/_profiler', |
|
|
|
'/_wdt', |
|
|
|
'/_wdt', |
|
|
|
'/service-worker.js', |
|
|
|
'/service-worker.js', |
|
|
|
|
|
|
|
'/manifest.webmanifest', |
|
|
|
'/robots.txt', |
|
|
|
'/robots.txt', |
|
|
|
'/assets/', |
|
|
|
'/assets/', |
|
|
|
'/icons/', |
|
|
|
'/icons/', |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
public function __construct( |
|
|
|
public function __construct( |
|
|
|
private readonly VisitRepository $visitRepository, |
|
|
|
private readonly VisitRepository $visitRepository |
|
|
|
private readonly Security $security, |
|
|
|
|
|
|
|
) { |
|
|
|
) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -40,15 +38,9 @@ class VisitTrackingListener |
|
|
|
$request = $event->getRequest(); |
|
|
|
$request = $event->getRequest(); |
|
|
|
$route = $request->getPathInfo(); |
|
|
|
$route = $request->getPathInfo(); |
|
|
|
|
|
|
|
|
|
|
|
// Exception: Always track article publish API calls |
|
|
|
foreach (self::EXCLUDED_ROUTES as $excludedRoute) { |
|
|
|
$isArticlePublish = str_starts_with($route, '/api/article/publish'); |
|
|
|
if (str_starts_with($route, $excludedRoute)) { |
|
|
|
|
|
|
|
return; |
|
|
|
// Skip tracking for excluded routes (API, profiler, assets, etc.) |
|
|
|
|
|
|
|
if (!$isArticlePublish) { |
|
|
|
|
|
|
|
foreach (self::EXCLUDED_ROUTES as $excludedRoute) { |
|
|
|
|
|
|
|
if (str_starts_with($route, $excludedRoute)) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|