status() public method

Set and get the status for the response.
public status ( string $key = null, string $status = null ) : string
$key string Optional. Set to `'code'` or `'message'` to return just the code or message of the status, otherwise returns the full status header.
$status string The code or message of the status you wish to set.
return string Returns the full HTTP status, with version, code and message or dending on $key just the code or message.
Example #1
0
 public function testStatus()
 {
     $response = new Response();
     $expected = 'HTTP/1.1 500 Internal Server Error';
     $result = $response->status(500);
     $this->assertEqual($expected, $result);
     $expected = 'HTTP/1.1 500 Internal Server Error';
     $result = $response->status('500');
     $this->assertEqual($expected, $result);
     $expected = 'HTTP/1.1 500 Internal Server Error';
     $result = $response->status('Internal Server Error');
     $this->assertEqual($expected, $result);
     $expected = 500;
     $result = $response->status('code', 'Internal Server Error');
     $this->assertEqual($expected, $result);
     $expected = 'Internal Server Error';
     $result = $response->status('message', 500);
     $this->assertEqual($expected, $result);
     $expected = 'HTTP/1.1 500 Internal Server Error';
     $result = $response->status();
     $this->assertEqual($expected, $result);
     $expected = 'HTTP/1.1 303 See Other';
     $result = $response->status('See Other');
     $this->assertEqual($expected, $result);
     $expected = false;
     $result = $response->status('foobar');
     $this->assertEqual($expected, $result);
 }
Example #2
0
 public function testMalformedStatus()
 {
     $expected = "HTTP/1.1 304 Not Modified";
     $message = join("\r\n", array('HTTP/1.1 304', 'Header: Value', 'Connection: close', 'Content-Type: application/json;charset=iso-8859-1', '', 'Test!'));
     $response = new Response(compact('message'));
     $result = $response->status();
     $this->assertEqual($expected, $result);
     $expected = "HTTP/1.1 500 Internal Server Error";
     $message = join("\r\n", array('HTTP/1.1 500', 'Header: Value', 'Connection: close', 'Content-Type: application/json;charset=iso-8859-1', '', 'Test!'));
     $response = new Response(compact('message'));
     $result = $response->status();
     $this->assertEqual($expected, $result);
 }