From 12e7a8d0dd42fa274193e1d53ccf011a168f2f6b Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Tue, 29 Sep 2015 13:18:10 -0400 Subject: [PATCH] Allow sources to have null contentType if serve is given one --- lib/Minify.php | 28 +++++++++++++++++++++++----- lib/Minify/SourceInterface.php | 2 +- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/Minify.php b/lib/Minify.php index ebde461..345c6a2 100644 --- a/lib/Minify.php +++ b/lib/Minify.php @@ -652,9 +652,24 @@ class Minify { $type = null; foreach ($this->sources as $source) { + $sourceType = $source->getContentType(); + + if (!empty($options['contentType'])) { + // just verify sources have null content type or match the options + if ($sourceType !== null && $sourceType !== $options['contentType']) { + // TODO better logging + Minify_Logger::log('ContentType mismatch'); + + $this->sources = array(); + return $options; + } + + continue; + } + if ($type === null) { - $type = $source->getContentType(); - } elseif ($source->getContentType() !== $type) { + $type = $sourceType; + } elseif ($sourceType !== $type) { // TODO better logging Minify_Logger::log('ContentType mismatch'); @@ -663,10 +678,13 @@ class Minify { return $options; } } - if (null === $type) { - $type = 'text/plain'; + + if (empty($options['contentType'])) { + if (null === $type) { + $type = 'text/plain'; + } + $options['contentType'] = $type; } - $options['contentType'] = $type; // last modified is needed for caching, even if setExpires is set if (!isset($options['lastModifiedTime'])) { diff --git a/lib/Minify/SourceInterface.php b/lib/Minify/SourceInterface.php index 31714c7..fa721f9 100644 --- a/lib/Minify/SourceInterface.php +++ b/lib/Minify/SourceInterface.php @@ -47,7 +47,7 @@ interface Minify_SourceInterface { /** * Get the content type * - * @return string + * @return string|null */ public function getContentType();