From 9aee3c0d9936f3061b52a19b5865d2ab7537a93f Mon Sep 17 00:00:00 2001 From: jtfnetoo Date: Wed, 1 Feb 2023 11:22:00 -0400 Subject: [PATCH] Informando quais formatos podem entrar no fluxo de download e permitindo identificar o mime do formato --- src/app/Enums/ReportFormatEnum.php | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/app/Enums/ReportFormatEnum.php b/src/app/Enums/ReportFormatEnum.php index 51168db..172230d 100644 --- a/src/app/Enums/ReportFormatEnum.php +++ b/src/app/Enums/ReportFormatEnum.php @@ -29,4 +29,45 @@ class ReportFormatEnum self::XLSX, ]; } + + /** + * @return string[] + */ + public static function downloadable(): array + { + return [ + self::PDF, + self::XML, + self::CSV, + self::DOCX, + self::ODT, + self::ODS, + self::XLSX, + ]; + } + + /** + * @param string $format + * @return string + */ + public static function getMimeType(string $format): string + { + switch ($format) { + case self::PDF: + return 'application/pdf'; + case self::XML: + return 'application/xml'; + case self::CSV: + return 'text/csv'; + case self::DOCX: + return 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; + case self::ODT: + return 'application/vnd.oasis.opendocument.text'; + case self::XLSX: + case self::ODS: + return 'application/vnd.oasis.opendocument.spreadsheet'; + default: + return 'text/html'; + } + } } \ No newline at end of file