/**
* Adds the Link HTTP header to the response.
*
* @author Kévin Dunglas <dunglas@gmail.com>
*
* @final
*/
class AddLinkHeaderListener implements EventSubscriberInterface
{ public function __construct( private readonly HttpHeaderSerializer
$serializer =
new HttpHeaderSerializer(),
) { } public function onKernelResponse(ResponseEvent
$event): void
{ if (!
$event->
isMainRequest()) { return;
} $linkProvider =
$event->
getRequest()->attributes->
get('_links'
);
if (!
$linkProvider instanceof LinkProviderInterface || !
$links =
$linkProvider->
getLinks()) {