Last active
February 19, 2020 15:32
-
-
Save Gompali/d53b84b0abfcaa9f25a2c80f9d6a59ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace App\Entity\EventListener; | |
use Symfony\Component\HttpFoundation\BinaryFileResponse; | |
use Symfony\Component\HttpKernel\Event\ResponseEvent; | |
class ResponseListener | |
{ | |
/** | |
* @var PdfConverterInterface | |
*/ | |
private $converter; | |
public function __construct(PdfConverterInterface $converter) | |
{ | |
$this->converter = $converter; | |
} | |
public function onKernelResponse(ResponseEvent $event) | |
{ | |
$response = $event->getResponse(); | |
if ('application/pdf' === $response->headers->get('accept')) { | |
$content = $response->getContent(); | |
return new BinaryFileResponse( | |
$this->converter->toPdfStream($content) | |
); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment