mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Changing the encoding method for "charset"
This commit is contained in:
parent
d4131152cd
commit
d1808db0df
2 changed files with 23 additions and 22 deletions
|
@ -298,11 +298,11 @@ class CakeResponse {
|
|||
protected $_body = null;
|
||||
|
||||
/**
|
||||
* Encoding string to send
|
||||
* The charset the response body is encoded with
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_encoding = 'UTF-8';
|
||||
protected $_charset = 'UTF-8';
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
|
@ -311,7 +311,7 @@ class CakeResponse {
|
|||
* - body: the rensonse text that should be sent to the client
|
||||
* - status: the HTTP status code to respond with
|
||||
* - type: a complete mime-type string or an extension mapepd in this class
|
||||
* - encoding: the encoding for the response body
|
||||
* - charset: the charset for the response body
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array()) {
|
||||
|
@ -324,8 +324,8 @@ class CakeResponse {
|
|||
if (isset($options['type'])) {
|
||||
$this->type($options['type']);
|
||||
}
|
||||
if (isset($options['encoding'])) {
|
||||
$this->encoding($options['encoding']);
|
||||
if (isset($options['charset'])) {
|
||||
$this->charset($options['charset']);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -334,6 +334,7 @@ class CakeResponse {
|
|||
*
|
||||
*/
|
||||
public function send() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -447,17 +448,17 @@ class CakeResponse {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the response encoding or charset
|
||||
* if $encoding is null the current encoding is returned
|
||||
* Sets the response charset
|
||||
* if $charset is null the current charset is returned
|
||||
*
|
||||
* @param string $encoding
|
||||
* @return string current status code
|
||||
* @param string $charset
|
||||
* @return string current charset
|
||||
*/
|
||||
public function encoding($encoding = null) {
|
||||
if (is_null($encoding)) {
|
||||
return $this->_encoding;
|
||||
public function charset($charset = null) {
|
||||
if (is_null($charset)) {
|
||||
return $this->_charset;
|
||||
}
|
||||
return $this->_encoding = $encoding;
|
||||
return $this->_charset = $charset;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,19 +12,19 @@ class CakeRequestTestCase extends CakeTestCase {
|
|||
public function testConstruct() {
|
||||
$response = new CakeResponse();
|
||||
$this->assertNull($response->body());
|
||||
$this->assertEquals($response->encoding(), 'UTF-8');
|
||||
$this->assertEquals($response->charset(), 'UTF-8');
|
||||
$this->assertEquals($response->type(), 'text/html');
|
||||
$this->assertEquals($response->statusCode(), 200);
|
||||
|
||||
$options = array(
|
||||
'body' => 'This is the body',
|
||||
'encoding' => 'my-custom-encoding',
|
||||
'charset' => 'my-custom-charset',
|
||||
'type' => 'mp3',
|
||||
'status' => '203'
|
||||
);
|
||||
$response = new CakeResponse($options);
|
||||
$this->assertEquals($response->body(), 'This is the body');
|
||||
$this->assertEquals($response->encoding(), 'my-custom-encoding');
|
||||
$this->assertEquals($response->charset(), 'my-custom-charset');
|
||||
$this->assertEquals($response->type(), 'audio/mpeg');
|
||||
$this->assertEquals($response->statusCode(), 203);
|
||||
}
|
||||
|
@ -42,15 +42,15 @@ class CakeRequestTestCase extends CakeTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Tests the encoding method
|
||||
* Tests the charset method
|
||||
*
|
||||
*/
|
||||
public function testEncoding() {
|
||||
public function testCharset() {
|
||||
$response = new CakeResponse();
|
||||
$this->assertEquals($response->encoding(), 'UTF-8');
|
||||
$response->encoding('iso-8859-1');
|
||||
$this->assertEquals($response->encoding(), 'iso-8859-1');
|
||||
$this->assertEquals($response->encoding('UTF-16'), 'UTF-16');
|
||||
$this->assertEquals($response->charset(), 'UTF-8');
|
||||
$response->charset('iso-8859-1');
|
||||
$this->assertEquals($response->charset(), 'iso-8859-1');
|
||||
$this->assertEquals($response->charset('UTF-16'), 'UTF-16');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue