Add method to view to allow adding request headers

This commit is contained in:
Timothy Warren 2017-04-12 11:14:16 -04:00
parent 57c6d6a34d
commit 9105b40b5e
3 changed files with 22 additions and 2 deletions

View File

@ -85,6 +85,19 @@ abstract class View
return $this->getOutput();
}
/**
* Add an http header
*
* @param string $name
* @param string|string[] $value
* @return ViewInterface
*/
public function addHeader(string $name, $value): ViewInterface
{
$this->response = $this->response->withHeader($name, $value);
return $this;
}
/**
* Set the output string
*

View File

@ -37,7 +37,7 @@ interface ViewInterface {
* @param mixed $string
* @return ViewInterface
*/
public function setOutput($string): ViewInterface;
public function setOutput($string): self;
/**
* Append additional output.
@ -45,7 +45,7 @@ interface ViewInterface {
* @param string $string
* @return ViewInterface
*/
public function appendOutput(string $string): ViewInterface;
public function appendOutput(string $string): self;
/**
* Get the current output as a string. Does not

View File

@ -63,6 +63,13 @@ class HttpViewTest extends Ion_TestCase {
$this->assertEquals(404, $view->response->getStatusCode());
}
public function testAddHeader()
{
$view = $this->view->addHeader('foo', 'bar');
$this->assertTrue($view->response->hasHeader('foo'));
$this->assertEquals(['bar'], $view->response->getHeader('foo'));
}
public function testSendDoubleRenderException()
{
$this->expectException(DoubleRenderException::class);