diff --git a/cake/libs/cake_response.php b/cake/libs/cake_response.php index dcfdb8a72..999c20298 100644 --- a/cake/libs/cake_response.php +++ b/cake/libs/cake_response.php @@ -492,6 +492,19 @@ class CakeResponse { * Sets the response content type. It can be either a file extension * which will be mapped internally to a mime-type or a string representing a mime-type * if $contentType is null the current content type is returned +* if $contentType is an associative array, it will be stored as a content type definition +* +* ### Setting the content type +* e.g `type('jpg');` +* +* ### Returning the current content type +* e.g `type();` +* +* ### Storing a content type definition +* e.g `type(array('keynote' => 'application/keynote'));` +* +* ### Replacing a content type definition +* e.g `type(array('jpg' => 'text/plain'));` * * @param string $contentType * @return string current content type @@ -500,6 +513,12 @@ class CakeResponse { if (is_null($contentType)) { return $this->_contentType; } + if (is_array($contentType)) { + $type = key($contentType); + $defitition = current($contentType); + $this->_mimeTypes[$type] = $defitition; + return $this->_contentType; + } if (isset($this->_mimeTypes[$contentType])) { $contentType = $this->_mimeTypes[$contentType]; $contentType = is_array($contentType) ? current($contentType) : $contentType; diff --git a/cake/tests/cases/libs/cake_response.test.php b/cake/tests/cases/libs/cake_response.test.php index 4d5596af4..cc7df03f9 100644 --- a/cake/tests/cases/libs/cake_response.test.php +++ b/cake/tests/cases/libs/cake_response.test.php @@ -83,6 +83,9 @@ class CakeResponseTestCase extends CakeTestCase { $this->assertEquals($response->type('wap'), 'text/vnd.wap.wml'); $this->assertEquals($response->type('xhtml-mobile'), 'application/vnd.wap.xhtml+xml'); $this->assertEquals($response->type('csv'), 'text/csv'); + + $response->type(array('keynote' => 'application/keynote')); + $this->assertEquals($response->type('keynote'), 'application/keynote'); } /**