diff --git a/src/View.php b/src/View.php index 5411aba..f8a4bbb 100644 --- a/src/View.php +++ b/src/View.php @@ -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 * diff --git a/src/ViewInterface.php b/src/ViewInterface.php index bf49b4d..8e5858b 100644 --- a/src/ViewInterface.php +++ b/src/ViewInterface.php @@ -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 diff --git a/tests/View/HttpViewTest.php b/tests/View/HttpViewTest.php index 5fd4f45..20c194d 100644 --- a/tests/View/HttpViewTest.php +++ b/tests/View/HttpViewTest.php @@ -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);