vendor/gollumsf/rest-doc-bundle/src/Controller/SwaggerUIController.php line 9

Open in your IDE?
  1. <?php
  2. namespace GollumSF\RestDocBundle\Controller;
  3. use GollumSF\RestDocBundle\Generator\OpenApiGeneratorInterface;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Twig\Environment;
  6. class SwaggerUIController {
  7.     
  8.     /** @var Environment */
  9.     private $twig;
  10.     /** @var OpenApiGeneratorInterface */
  11.     private $openApiGenerator;
  12.     
  13.     public function __construct(
  14.         OpenApiGeneratorInterface $openApiGenerator
  15.     ) {
  16.         $this->openApiGenerator $openApiGenerator;
  17.     }
  18.     public function setTwig(Environment $twig): self {
  19.         $this->twig $twig;
  20.         return $this;
  21.     }
  22.     public function __invoke() {
  23.         if (!$this->twig) {
  24.             throw new \LogicException(sprintf('%s service not declared. install Symfony Twig'Environment::class));
  25.         }
  26.         return new Response(
  27.             $this->twig->render('@GollumSFRestDoc/SwaggerUI/index.html.twig', [
  28.                 'swaggerData' => $this->openApiGenerator->generate()
  29.             ]),
  30.             Response::HTTP_OK,
  31.             [ 'Content-Type' => 'text/html' ]
  32.         );
  33.     }
  34. }