mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Adding the ability to add custom content types to CakeResponse
This commit is contained in:
parent
077f71aaa1
commit
87eb1ec697
2 changed files with 22 additions and 0 deletions
|
@ -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;
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue