vendor/nelmio/api-doc-bundle/Nelmio/ApiDocBundle/EventListener/RequestListener.php line 47

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the NelmioApiDocBundle.
  4.  *
  5.  * (c) Nelmio <hello@nelm.io>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Nelmio\ApiDocBundle\EventListener;
  11. use Nelmio\ApiDocBundle\Extractor\ApiDocExtractor;
  12. use Nelmio\ApiDocBundle\Formatter\FormatterInterface;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\HttpKernel\HttpKernelInterface;
  15. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  16. class RequestListener
  17. {
  18.     /**
  19.      * @var \Nelmio\ApiDocBundle\Extractor\ApiDocExtractor
  20.      */
  21.     protected $extractor;
  22.     /**
  23.      * @var \Nelmio\ApiDocBundle\Formatter\FormatterInterface
  24.      */
  25.     protected $formatter;
  26.     /**
  27.      * @var string
  28.      */
  29.     protected $parameter;
  30.     public function __construct(ApiDocExtractor $extractorFormatterInterface $formatter$parameter)
  31.     {
  32.         $this->extractor $extractor;
  33.         $this->formatter $formatter;
  34.         $this->parameter $parameter;
  35.     }
  36.     /**
  37.      * {@inheritdoc}
  38.      */
  39.     public function onKernelRequest(GetResponseEvent $event)
  40.     {
  41.         if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
  42.             return;
  43.         }
  44.         $request $event->getRequest();
  45.         if (!$request->query->has($this->parameter)) {
  46.             return;
  47.         }
  48.         $controller $request->attributes->get('_controller');
  49.         $route      $request->attributes->get('_route');
  50.         if (null !== $annotation $this->extractor->get($controller$route)) {
  51.             $result $this->formatter->formatOne($annotation);
  52.             $event->setResponse(new Response($result200, array(
  53.                 'Content-Type' => 'text/html'
  54.             )));
  55.         }
  56.     }
  57. }