Permalink
Browse files

Merge pull request #11335 from saeideng/response/gettype

Implement response::getType()
2 parents d913b2e + 1b3cb01 commit 5cbedd382f57fee506d67cf94eb00f05c35c0b1e @markstory markstory committed Oct 18, 2017
Showing with 35 additions and 3 deletions.
  1. +13 −3 src/Http/Response.php
  2. +22 −0 tests/TestCase/Http/ResponseTest.php
View
@@ -1047,14 +1047,14 @@ public function httpCodes($code = null)
public function type($contentType = null)
{
if ($contentType === null) {
- return $this->_contentType;
+ return $this->getType();
}
if (is_array($contentType)) {
foreach ($contentType as $type => $definition) {
$this->_mimeTypes[$type] = $definition;
}
- return $this->_contentType;
+ return $this->getType();
}
if (isset($this->_mimeTypes[$contentType])) {
$contentType = $this->_mimeTypes[$contentType];
@@ -1070,6 +1070,16 @@ public function type($contentType = null)
}
/**
+ * Returns the current content type.
+ *
+ * @return string
+ */
+ public function getType()
+ {
+ return $this->_contentType;
+ }
+
+ /**
* Get an updated response with the content type set.
*
* If you attempt to set the type on a 304 or 204 status code response, the
@@ -1168,7 +1178,7 @@ public function charset($charset = null)
}
/**
- * Retruns the current charset.
+ * Returns the current charset.
*
* @return string
*/
@@ -214,6 +214,28 @@ public function testType()
}
/**
+ * Tests the getType method
+ *
+ * @return void
+ */
+ public function testGetType()
+ {
+ $response = new Response();
+ $this->assertEquals('text/html', $response->getType());
+ $response->type('pdf');
+ $this->assertEquals('application/pdf', $response->getType());
+
+ $this->assertEquals(
+ 'custom/stuff',
+ $response->withType('custom/stuff')->getType()
+ );
+ $this->assertEquals(
+ 'application/json',
+ $response->withType('json')->getType()
+ );
+ }
+
+ /**
* Tests the withType method
*
* @return void

0 comments on commit 5cbedd3

Please sign in to comment.