<?php
declare(strict_types=1);
namespace App\EventSubscriber;
use App\Service\DocumentationGeneratorService;
use HarmBandstra\SwaggerUiBundle\Controller\DocsController;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class DocsSubscriber implements EventSubscriberInterface
{
/**
* @var DocumentationGeneratorService
*/
private $documentationGeneratorService;
public function __construct(DocumentationGeneratorService $documentationGeneratorService)
{
$this->documentationGeneratorService = $documentationGeneratorService;
}
/**
* @see https://symfony.com/doc/current/event_dispatcher/before_after_filters.html
*
* @param ControllerEvent $event
* @return Response|void
* @throws \Exception
*/
public function onKernelController(ControllerEvent $event)
{
$controller = $event->getController();
if (is_array($controller) && $controller[0] instanceof DocsController) {
$this->documentationGeneratorService->getDocumentation();
}
}
/**
* Returns an array of event names this subscriber wants to listen to.
* @return array The event names to listen to
*/
public static function getSubscribedEvents()
{
return [
KernelEvents::CONTROLLER => 'onKernelController',
];
}
}