4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\EventListener;
14 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
15 use Symfony\Component\HttpKernel\KernelEvents;
16 use Symfony\Component\HttpKernel\Event\GetResponseEvent;
19 * Adds configured formats to each request.
21 * @author Gildas Quemener <gildas.quemener@gmail.com>
23 class AddRequestFormatsListener implements EventSubscriberInterface
31 * @param array $formats
33 public function __construct(array $formats)
35 $this->formats = $formats;
39 * Adds request formats.
41 * @param GetResponseEvent $event
43 public function onKernelRequest(GetResponseEvent $event)
45 foreach ($this->formats as $format => $mimeTypes) {
46 $event->getRequest()->setFormat($format, $mimeTypes);
53 public static function getSubscribedEvents()
55 return array(KernelEvents::REQUEST => array('onKernelRequest', 1));