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\Event\GetResponseEvent;
16 use Symfony\Component\HttpKernel\KernelEvents;
19 * Adds configured formats to each request.
21 * @author Gildas Quemener <gildas.quemener@gmail.com>
23 class AddRequestFormatsListener implements EventSubscriberInterface
27 public function __construct(array $formats)
29 $this->formats = $formats;
33 * Adds request formats.
35 public function onKernelRequest(GetResponseEvent $event)
37 $request = $event->getRequest();
38 foreach ($this->formats as $format => $mimeTypes) {
39 $request->setFormat($format, $mimeTypes);
46 public static function getSubscribedEvents()
48 return array(KernelEvents::REQUEST => array('onKernelRequest', 1));