mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-09-01 21:00:58 +00:00
* refactor: stabilize model identities for domain migration * refactor: extract module platform context * refactor: assign models to domain contexts * refactor: extract ai platform context * refactor: extract storage platform context * refactor: extract mail platform context * refactor: extract pdf platform context * refactor: extract operations platform context * refactor: move installation into operations platform * refactor: extract money domain context * refactor: extract taxation domain context * refactor: extract catalog domain context * refactor: extract metadata domain context * refactor: extract reporting domain context * refactor: extract purchases domain context * refactor: extract receivables domain context * refactor: extract accounts domain context * refactor: complete reporting statement boundary * refactor: extract contacts domain context * refactor: extract sales domain context * refactor: remove legacy application layers * fix: migrate legacy bouncer role identities
49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Platform\Pdf\Rendering;
|
|
|
|
use Illuminate\Http\Response;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
class GotenbergPdfResponse implements ResponseStream
|
|
{
|
|
protected ResponseInterface $response;
|
|
|
|
public function __construct($stream)
|
|
{
|
|
$this->response = $stream;
|
|
}
|
|
|
|
public function stream(string $filename = 'document.pdf'): Response
|
|
{
|
|
return $this->respond($filename, 'inline');
|
|
}
|
|
|
|
public function download(string $filename = 'document.pdf'): Response
|
|
{
|
|
return $this->respond($filename, 'attachment');
|
|
}
|
|
|
|
public function output(): string
|
|
{
|
|
$body = $this->response->getBody();
|
|
|
|
// getContents() reads from wherever the stream currently sits, so a
|
|
// second call would hand back nothing. Rewind so output() is repeatable
|
|
// and safe to mix with stream()/download() on the same instance.
|
|
if ($body->isSeekable()) {
|
|
$body->rewind();
|
|
}
|
|
|
|
return $body->getContents();
|
|
}
|
|
|
|
private function respond(string $filename, string $disposition): Response
|
|
{
|
|
return new Response($this->output(), 200, [
|
|
'Content-Type' => 'application/pdf',
|
|
'Content-Disposition' => $disposition.'; filename="'.$filename.'"',
|
|
]);
|
|
}
|
|
}
|