<?php declare(strict_types=1);
namespace Shopware\Commercial\Licensing\Subscriber;
use Shopware\Commercial\Licensing\LicenseReporter;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\RequestEvent;
/**
* @internal
*/
final class LicenseReportListener
{
private LicenseReporter $reporter;
/**
* @internal
*/
public function __construct(LicenseReporter $reporter)
{
$this->reporter = $reporter;
}
public function __invoke(RequestEvent $event): void
{
$request = $event->getRequest();
if ($request->headers->has('sw-license-toggle')) {
$this->reporter->reportNow((string) $request->headers->get('sw-license-toggle'));
$event->setResponse(new Response('', Response::HTTP_NO_CONTENT));
}
if ($request->attributes->get('_route') !== 'api.action.store.plugin.search') {
return;
}
$this->reporter->report();
}
}