Skip to content
Permalink
Browse files

Adding the ability to add custom content types to CakeResponse

  • Loading branch information...
lorenzo committed Aug 1, 2010
1 parent 077f71a commit 87eb1ec697c4e817cf17b7a76ad28c593093fbef
Showing with 22 additions and 0 deletions.
  1. +19 −0 cake/libs/cake_response.php
  2. +3 −0 cake/tests/cases/libs/cake_response.test.php
@@ -492,6 +492,19 @@ public function httpCodes($code = null) {
* 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 @@ public function type($contentType = null) {
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;
@@ -83,6 +83,9 @@ public function testType() {
$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');
}
/**

0 comments on commit 87eb1ec

Please sign in to comment.
You can’t perform that action at this time.