summaryrefslogtreecommitdiffstats
path: root/src/Controller/Output.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Controller/Output.php')
-rw-r--r--src/Controller/Output.php26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/Controller/Output.php b/src/Controller/Output.php
index ff0ed80..8eecc8b 100644
--- a/src/Controller/Output.php
+++ b/src/Controller/Output.php
@@ -290,7 +290,8 @@ trait Output
*/
protected function getContentType($format)
{
- if (\Jasny\str_contains($format, '/')) { // Already MIME
+ // Check if it's already MIME
+ if (\Jasny\str_contains($format, '/')) {
return $format;
}
@@ -376,12 +377,12 @@ trait Output
}
/**
- * Output result
- *
- * @param mixed $data
- * @param string $format Output format as MIME or extension
+ * Set the content type for the output
+ *
+ * @param string $format
+ * @return string
*/
- public function output($data, $format = null)
+ protected function outputContentType($format)
{
if (!isset($format)) {
$contentType = $this->getResponse()->getHeaderLine('Content-Type');
@@ -395,6 +396,19 @@ trait Output
$contentType = $this->getContentType($format);
$this->setResponseHeader('Content-Type', $contentType);
}
+
+ return $contentType;
+ }
+
+ /**
+ * Output result
+ *
+ * @param mixed $data
+ * @param string $format Output format as MIME or extension
+ */
+ public function output($data, $format = null)
+ {
+ $contentType = $this->outputContentType($format);
try {
$content = $this->serializeData($data, $contentType);