Browse Source

Add Response::getCharset() and deprecate Response::charset()

Michael Hoffmann 8 years ago
parent
commit
4ff3531b31
2 changed files with 13 additions and 2 deletions
  1. 11 1
      src/Http/Response.php
  2. 2 1
      tests/TestCase/Http/ResponseTest.php

+ 11 - 1
src/Http/Response.php

@@ -1153,7 +1153,7 @@ class Response implements ResponseInterface
      *
      * @param string|null $charset Character set string.
      * @return string Current charset
-     * @deprecated 3.4.0 Use withCharset() instead.
+     * @deprecated 3.5.0 Use getCharset()/withCharset() instead.
      */
     public function charset($charset = null)
     {
@@ -1167,6 +1167,16 @@ class Response implements ResponseInterface
     }
 
     /**
+     * Retruns the current charset.
+     *
+     * @return string
+     */
+    public function getCharset()
+    {
+        return $this->_charset;
+    }
+
+    /**
      * Get a new instance with an updated charset.
      *
      * @param string $charset Character set string.

+ 2 - 1
tests/TestCase/Http/ResponseTest.php

@@ -144,7 +144,7 @@ class ResponseTest extends TestCase
     }
 
     /**
-     * Tests withCharset method
+     * Tests getCharset/withCharset methods
      *
      * @return void
      */
@@ -155,6 +155,7 @@ class ResponseTest extends TestCase
 
         $new = $response->withCharset('iso-8859-1');
         $this->assertNotContains('iso', $response->getHeaderLine('Content-Type'), 'Old instance not changed');
+        $this->assertSame('iso-8859-1', $new->getCharset());
 
         $this->assertEquals('text/html; charset=iso-8859-1', $new->getHeaderLine('Content-Type'));
     }