diff --git a/src/app/Enums/ContentDispositionEnum.php b/src/app/Enums/ContentDispositionEnum.php new file mode 100644 index 0000000..5a28c06 --- /dev/null +++ b/src/app/Enums/ContentDispositionEnum.php @@ -0,0 +1,20 @@ +client = $client; - $this->format = ReportFormatEnum::HTML; + $this->setFormat(ReportFormatEnum::HTML); + $this->setContentDisposition(ContentDispositionEnum::INLINE); } /** @@ -193,13 +200,20 @@ class JasperServerRequestService implements JasperServerRequestServiceContract } /** - * @param string $uri - * @param string|null $filename * @return string */ - public function call(string $uri, ?string $filename = null): string + public function getReport(): string + { + return $this->report; + } + + /** + * @param string $uri + * @return $this + */ + public function call(string $uri): self { - $report = $this->client->reportService()->runReport( + $this->report = $this->client->reportService()->runReport( $uri, $this->format, $this->pages, @@ -212,11 +226,30 @@ class JasperServerRequestService implements JasperServerRequestServiceContract $this->transformerKey ); + return $this; + } + + /** + * @return string + */ + public function inline(): string + { + $this->setContentDisposition(ContentDispositionEnum::INLINE); + return $this->getReport(); + } + + /** + * @param string|null $filename + * @return string + */ + public function download(?string $filename): string + { if (in_array($this->format, ReportFormatEnum::downloadable())) { - $this->setHeader($report, $filename); + $this->setContentDisposition(ContentDispositionEnum::ATTACHMENT); + $this->setHeader($this->report, $filename); } - return $report; + return $this->getReport(); } /**