Skip to content

Instantly share code, notes, and snippets.

@anboo
Created March 12, 2017 16:31
Show Gist options
  • Save anboo/f3a4b93feb76a58f8aae8d5d8d6c42e8 to your computer and use it in GitHub Desktop.
Save anboo/f3a4b93feb76a58f8aae8d5d8d6c42e8 to your computer and use it in GitHub Desktop.
<?php
namespace AppBundle\EventListener\Core;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use JMS\DiExtraBundle\Annotation as DI;
class ApiAnnotationControllerListener implements EventSubscriberInterface
{
public function onGetResponseForController(GetResponseForControllerResultEvent $event)
{
$array = $event->getControllerResult();
$convertedArray = $this->convert($array);
$event->setResponse(new JsonResponse($convertedArray));
}
public static function getSubscribedEvents()
{
return array(
KernelEvents::VIEW => 'onGetResponseForController',
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment