Skip to content

Instantly share code, notes, and snippets.

@anboo
Created March 12, 2017 16:31
Show Gist options
  • Select an option

  • Save anboo/f3a4b93feb76a58f8aae8d5d8d6c42e8 to your computer and use it in GitHub Desktop.

Select an option

Save anboo/f3a4b93feb76a58f8aae8d5d8d6c42e8 to your computer and use it in GitHub Desktop.

Revisions

  1. anboo created this gist Mar 12, 2017.
    27 changes: 27 additions & 0 deletions php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    <?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',
    );
    }
    }