src/EventSubscriber/DocsSubscriber.php line 32

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\EventSubscriber;
  4. use App\Service\DocumentationGeneratorService;
  5. use HarmBandstra\SwaggerUiBundle\Controller\DocsController;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  9. use Symfony\Component\HttpKernel\KernelEvents;
  10. class DocsSubscriber implements EventSubscriberInterface
  11. {
  12.     /**
  13.      * @var DocumentationGeneratorService
  14.      */
  15.     private $documentationGeneratorService;
  16.     public function __construct(DocumentationGeneratorService $documentationGeneratorService)
  17.     {
  18.         $this->documentationGeneratorService $documentationGeneratorService;
  19.     }
  20.     /**
  21.      * @see https://symfony.com/doc/current/event_dispatcher/before_after_filters.html
  22.      *
  23.      * @param ControllerEvent $event
  24.      * @return Response|void
  25.      * @throws \Exception
  26.      */
  27.     public function onKernelController(ControllerEvent $event)
  28.     {
  29.         $controller $event->getController();
  30.         if (is_array($controller) && $controller[0] instanceof DocsController) {
  31.             $this->documentationGeneratorService->getDocumentation();
  32.         }
  33.     }
  34.     /**
  35.      * Returns an array of event names this subscriber wants to listen to.
  36.      * @return array The event names to listen to
  37.      */
  38.     public static function getSubscribedEvents()
  39.     {
  40.         return [
  41.             KernelEvents::CONTROLLER => 'onKernelController',
  42.         ];
  43.     }
  44. }