vendor/stefandoorn/sitemap-plugin/src/Controller/AbstractController.php line 22

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace SitemapPlugin\Controller;
  4. use Gaufrette\StreamMode;
  5. use SitemapPlugin\Filesystem\Reader;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\HttpFoundation\StreamedResponse;
  8. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  9. abstract class AbstractController
  10. {
  11.     protected Reader $reader;
  12.     public function __construct(Reader $reader)
  13.     {
  14.         $this->reader $reader;
  15.     }
  16.     protected function createResponse(string $path): Response
  17.     {
  18.         if (!$this->reader->has($path)) {
  19.             throw new NotFoundHttpException(\sprintf('File "%s" not found'$path));
  20.         }
  21.         $response = new StreamedResponse(function () use ($path): void {
  22.             $stream $this->reader->getStream($path);
  23.             $stream->open(new StreamMode('r'));
  24.             while (!$stream->eof()) {
  25.                 echo $stream->read(100000);
  26.             }
  27.             $stream->close();
  28.         });
  29.         $response->headers->set('Content-Type''application/xml');
  30.         return $response;
  31.     }
  32. }