<?php
namespace App\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class ResponseEventListener implements EventSubscriberInterface
{
const VERSION_HEADER_NAME = 'Api-Version';
/**
* @var string
*/
protected $apiVersion;
public function __construct($apiVersion)
{
$this->apiVersion = $apiVersion;
}
public static function getSubscribedEvents()
{
return [
KernelEvents::RESPONSE => [['onResponse', 20]],
];
}
public function onResponse(ResponseEvent $event)
{
$response = $event->getResponse();
$response->headers->set(self::VERSION_HEADER_NAME, $this->apiVersion);
}
}