mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
allow additional status codes through constructor
through $options['statusCodes']
This commit is contained in:
parent
05b2196cd5
commit
84eb46dbdc
2 changed files with 19 additions and 0 deletions
|
@ -379,6 +379,7 @@ class CakeResponse {
|
|||
*
|
||||
* @param array $options list of parameters to setup the response. Possible values are:
|
||||
* - body: the response text that should be sent to the client
|
||||
* - codes: additional allowable response codes
|
||||
* - status: the HTTP status code to respond with
|
||||
* - type: a complete mime-type string or an extension mapped in this class
|
||||
* - charset: the charset for the response body
|
||||
|
@ -387,6 +388,9 @@ class CakeResponse {
|
|||
if (isset($options['body'])) {
|
||||
$this->body($options['body']);
|
||||
}
|
||||
if (isset($options['statusCodes'])) {
|
||||
$this->httpCodes($options['statusCodes']);
|
||||
}
|
||||
if (isset($options['status'])) {
|
||||
$this->statusCode($options['status']);
|
||||
}
|
||||
|
|
|
@ -66,6 +66,21 @@ class CakeResponseTest extends CakeTestCase {
|
|||
$this->assertEquals('my-custom-charset', $response->charset());
|
||||
$this->assertEquals('audio/mpeg', $response->type());
|
||||
$this->assertEquals(203, $response->statusCode());
|
||||
|
||||
$options = array(
|
||||
'body' => 'This is the body',
|
||||
'charset' => 'my-custom-charset',
|
||||
'type' => 'mp3',
|
||||
'status' => '422',
|
||||
'statusCodes' => array(
|
||||
422 => 'Unprocessable Entity'
|
||||
)
|
||||
);
|
||||
$response = new CakeResponse($options);
|
||||
$this->assertEquals($options['body'], $response->body());
|
||||
$this->assertEquals($options['charset'], $response->charset());
|
||||
$this->assertEquals($response->getMimeType($options['type']), $response->type());
|
||||
$this->assertEquals($options['status'], $response->statusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue