Allow bulk storing/updating of mime types. Closes #2844

This commit is contained in:
ADmad 2012-05-03 01:39:12 +05:30
parent e7fa2a526f
commit 49f8e73ab3
2 changed files with 48 additions and 47 deletions

View file

@ -328,7 +328,7 @@ class CakeResponse {
/** /**
* Holds cookies to be sent to the client * Holds cookies to be sent to the client
* *
* @var array * @var array
*/ */
protected $_cookies = array(); protected $_cookies = array();
@ -384,7 +384,7 @@ class CakeResponse {
* Sets the cookies that have been added via static method CakeResponse::addCookie() * Sets the cookies that have been added via static method CakeResponse::addCookie()
* before any other output is sent to the client. * before any other output is sent to the client.
* Will set the cookies in the order they have been set. * Will set the cookies in the order they have been set.
* *
* @return void * @return void
*/ */
protected function _setCookies() { protected function _setCookies() {
@ -595,7 +595,7 @@ class CakeResponse {
* Sets the response content type. It can be either a file extension * 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 * 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 null the current content type is returned
* if $contentType is an associative array, it will be stored as a content type definition * if $contentType is an associative array, content type definitions will be stored/replaced
* *
* ### Setting the content type * ### Setting the content type
* *
@ -605,9 +605,9 @@ class CakeResponse {
* *
* e.g `type();` * e.g `type();`
* *
* ### Storing a content type definition * ### Storing content type definitions
* *
* e.g `type(array('keynote' => 'application/keynote'));` * e.g `type(array('keynote' => 'application/keynote', 'bat' => 'application/bat'));`
* *
* ### Replacing a content type definition * ### Replacing a content type definition
* *
@ -621,9 +621,9 @@ class CakeResponse {
return $this->_contentType; return $this->_contentType;
} }
if (is_array($contentType)) { if (is_array($contentType)) {
$type = key($contentType); foreach ($contentType as $type => $definition) {
$defitition = current($contentType); $this->_mimeTypes[$type] = $definition;
$this->_mimeTypes[$type] = $defitition; }
return $this->_contentType; return $this->_contentType;
} }
if (isset($this->_mimeTypes[$contentType])) { if (isset($this->_mimeTypes[$contentType])) {
@ -800,12 +800,12 @@ class CakeResponse {
/** /**
* Sets the Cache-Control must-revalidate directive. * Sets the Cache-Control must-revalidate directive.
* must-revalidate indicates that the response should not be served * must-revalidate indicates that the response should not be served
* stale by a cache under any cirumstance without first revalidating * stale by a cache under any cirumstance without first revalidating
* with the origin. * with the origin.
* If called with no parameters, this function will return wheter must-revalidate is present. * If called with no parameters, this function will return wheter must-revalidate is present.
* *
* @param int $seconds if null, the method will return the current * @param int $seconds if null, the method will return the current
* must-revalidate value * must-revalidate value
* @return boolean * @return boolean
*/ */
@ -886,8 +886,8 @@ class CakeResponse {
} }
/** /**
* Sets the response as Not Modified by removing any body contents * Sets the response as Not Modified by removing any body contents
* setting the status code to "304 Not Modified" and removing all * setting the status code to "304 Not Modified" and removing all
* conflicting headers * conflicting headers
* *
* @return void * @return void
@ -911,11 +911,11 @@ class CakeResponse {
/** /**
* Sets the Vary header for the response, if an array is passed, * Sets the Vary header for the response, if an array is passed,
* values will be imploded into a comma separated string. If no * values will be imploded into a comma separated string. If no
* parameters are passed, then an array with the current Vary header * parameters are passed, then an array with the current Vary header
* value is returned * value is returned
* *
* @param string|array $cacheVariances a single Vary string or a array * @param string|array $cacheVariances a single Vary string or a array
* containig the list for variances. * containig the list for variances.
* @return array * @return array
**/ **/
@ -932,22 +932,22 @@ class CakeResponse {
/** /**
* Sets the response Etag, Etags are a strong indicative that a response * Sets the response Etag, Etags are a strong indicative that a response
* can be cached by a HTTP client. A bad way of generaing Etags is * can be cached by a HTTP client. A bad way of generaing Etags is
* creating a hash of the response output, instead generate a unique * creating a hash of the response output, instead generate a unique
* hash of the unique components that identifies a request, such as a * hash of the unique components that identifies a request, such as a
* modification time, a resource Id, and anything else you consider it * modification time, a resource Id, and anything else you consider it
* makes it unique. * makes it unique.
* *
* Second parameter is used to instuct clients that the content has * Second parameter is used to instuct clients that the content has
* changed, but sematicallly, it can be used as the same thing. Think * changed, but sematicallly, it can be used as the same thing. Think
* for instance of a page with a hit counter, two different page views * for instance of a page with a hit counter, two different page views
* are equivalent, but they differ by a few bytes. This leaves off to * are equivalent, but they differ by a few bytes. This leaves off to
* the Client the decision of using or not the cached page. * the Client the decision of using or not the cached page.
* *
* If no parameters are passed, current Etag header is returned. * If no parameters are passed, current Etag header is returned.
* *
* @param string $hash the unique has that identifies this resposnse * @param string $hash the unique has that identifies this resposnse
* @param boolean $weak whether the response is semantically the same as * @param boolean $weak whether the response is semantically the same as
* other with th same hash or not * other with th same hash or not
* @return string * @return string
**/ **/
@ -965,7 +965,7 @@ class CakeResponse {
* Returns a DateTime object initialized at the $time param and using UTC * Returns a DateTime object initialized at the $time param and using UTC
* as timezone * as timezone
* *
* @param string|int|DateTime $time * @param string|int|DateTime $time
* @return DateTime * @return DateTime
*/ */
protected function _getUTCDate($time = null) { protected function _getUTCDate($time = null) {
@ -1043,16 +1043,16 @@ class CakeResponse {
} }
/** /**
* Checks whether a response has not been modified according to the 'If-None-Match' * Checks whether a response has not been modified according to the 'If-None-Match'
* (Etags) and 'If-Modified-Since' (last modification date) request * (Etags) and 'If-Modified-Since' (last modification date) request
* headers headers. If the response is detected to be not modified, it * headers headers. If the response is detected to be not modified, it
* is marked as so accordingly so the client can be informed of that. * is marked as so accordingly so the client can be informed of that.
* *
* In order to mark a response as not modified, you need to set at least * In order to mark a response as not modified, you need to set at least
* the Last-Modified response header or a response etag to be compared * the Last-Modified response header or a response etag to be compared
* with the request itself * with the request itself
* *
* @return boolean whether the response was marked as not modified or * @return boolean whether the response was marked as not modified or
* not * not
**/ **/
public function checkNotModified(CakeRequest $request) { public function checkNotModified(CakeRequest $request) {
@ -1087,19 +1087,19 @@ class CakeResponse {
/** /**
* Getter/Setter for cookie configs * Getter/Setter for cookie configs
* *
* This method acts as a setter/getter depending on the type of the argument. * This method acts as a setter/getter depending on the type of the argument.
* If the method is called with no arguments, it returns all configurations. * If the method is called with no arguments, it returns all configurations.
* *
* If the method is called with a string as argument, it returns either the * If the method is called with a string as argument, it returns either the
* given configuration if it is set, or null, if it's not set. * given configuration if it is set, or null, if it's not set.
* *
* If the method is called with an array as argument, it will set the cookie * If the method is called with an array as argument, it will set the cookie
* configuration to the cookie container. * configuration to the cookie container.
* *
* @param $options Either null to get all cookies, string for a specific cookie * @param $options Either null to get all cookies, string for a specific cookie
* or array to set cookie. * or array to set cookie.
* *
* ### Options (when setting a configuration) * ### Options (when setting a configuration)
* - name: The Cookie name * - name: The Cookie name
* - value: Value of the cookie * - value: Value of the cookie
@ -1108,21 +1108,21 @@ class CakeResponse {
* - domain: Domain the cookie is for. * - domain: Domain the cookie is for.
* - secure: Is the cookie https? * - secure: Is the cookie https?
* - httpOnly: Is the cookie available in the client? * - httpOnly: Is the cookie available in the client?
* *
* ## Examples * ## Examples
* *
* ### Getting all cookies * ### Getting all cookies
* *
* `$this->cookie()` * `$this->cookie()`
* *
* ### Getting a certain cookie configuration * ### Getting a certain cookie configuration
* *
* `$this->cookie('MyCookie')` * `$this->cookie('MyCookie')`
* *
* ### Setting a cookie configuration * ### Setting a cookie configuration
* *
* `$this->cookie((array) $options)` * `$this->cookie((array) $options)`
* *
* @return mixed * @return mixed
*/ */
public function cookie($options = null) { public function cookie($options = null) {

View file

@ -118,8 +118,9 @@ class CakeResponseTest extends CakeTestCase {
$this->assertEquals('application/vnd.wap.xhtml+xml', $response->type('xhtml-mobile')); $this->assertEquals('application/vnd.wap.xhtml+xml', $response->type('xhtml-mobile'));
$this->assertEquals('text/csv', $response->type('csv')); $this->assertEquals('text/csv', $response->type('csv'));
$response->type(array('keynote' => 'application/keynote')); $response->type(array('keynote' => 'application/keynote', 'bat' => 'application/bat'));
$this->assertEquals('application/keynote', $response->type('keynote')); $this->assertEquals('application/keynote', $response->type('keynote'));
$this->assertEquals('application/bat', $response->type('bat'));
$this->assertFalse($response->type('wackytype')); $this->assertFalse($response->type('wackytype'));
} }
@ -925,7 +926,7 @@ class CakeResponseTest extends CakeTestCase {
/** /**
* Test cookie setting * Test cookie setting
* *
* @return void * @return void
*/ */
public function testCookieSettings() { public function testCookieSettings() {