Adding the ability to add custom content types to CakeResponse

This commit is contained in:
José Lorenzo Rodríguez 2010-08-01 14:22:02 -04:30
parent 077f71aaa1
commit 87eb1ec697
2 changed files with 22 additions and 0 deletions

View file

@ -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;

View file

@ -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');
}
/**