Skip to content

Instantly share code, notes, and snippets.

@viniciusss
Created October 30, 2015 12:51
Show Gist options
  • Save viniciusss/5878cb48cc0c157d8bd0 to your computer and use it in GitHub Desktop.
Save viniciusss/5878cb48cc0c157d8bd0 to your computer and use it in GitHub Desktop.
<?php
namespace AppBundle\EventListener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
class RequestListener
{
public function onKernelRequest(GetResponseEvent $event)
{
if (0 === strpos($event->getRequest()->headers->get('Content-Type'), 'application/json')) {
$event->getRequest()->headers->set('Content-Type', 'application/json');
$data = json_decode($event->getRequest()->getContent(), true);
$event->getRequest()->request->replace(is_array($data) ? $data : array());
}
}
}
app.listener.request:
class: AppBundle\EventListener\RequestListener
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment