mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Add CakeResponse::location()
This method provides an easy to use interface to get/set the location header in a response object. This is primarily to facilitate future development in 3.x
This commit is contained in:
parent
72508cb260
commit
2df873412c
2 changed files with 28 additions and 0 deletions
|
@ -584,6 +584,22 @@ class CakeResponse {
|
|||
return $this->_headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Acccessor for the location header.
|
||||
*
|
||||
* Get/Set the Location header value.
|
||||
* @param null|string $url Either null to get the current location, or a string to set one.
|
||||
* @return string|null When setting the location null will be returned. When reading the location
|
||||
* a string of the current location header value (if any) will be returned.
|
||||
*/
|
||||
public function location($url = null) {
|
||||
if ($url === null) {
|
||||
$headers = $this->header();
|
||||
return isset($headers['Location']) ? $headers['Location'] : null;
|
||||
}
|
||||
$this->header('Location', $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Buffers the response message to be sent
|
||||
* if $content is null the current buffer is returned
|
||||
|
|
|
@ -1481,4 +1481,16 @@ class CakeResponseTest extends CakeTestCase {
|
|||
$result = $response->send();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the location method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLocation() {
|
||||
$response = new CakeResponse();
|
||||
$this->assertNull($response->location());
|
||||
$this->assertNull($response->location('http://example.org'));
|
||||
$this->assertEquals('http://example.org', $response->location());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue