Add method to view to allow adding request headers
This commit is contained in:
parent
57c6d6a34d
commit
9105b40b5e
13
src/View.php
13
src/View.php
@ -85,6 +85,19 @@ abstract class View
|
|||||||
return $this->getOutput();
|
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
|
* Set the output string
|
||||||
*
|
*
|
||||||
|
@ -37,7 +37,7 @@ interface ViewInterface {
|
|||||||
* @param mixed $string
|
* @param mixed $string
|
||||||
* @return ViewInterface
|
* @return ViewInterface
|
||||||
*/
|
*/
|
||||||
public function setOutput($string): ViewInterface;
|
public function setOutput($string): self;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append additional output.
|
* Append additional output.
|
||||||
@ -45,7 +45,7 @@ interface ViewInterface {
|
|||||||
* @param string $string
|
* @param string $string
|
||||||
* @return ViewInterface
|
* @return ViewInterface
|
||||||
*/
|
*/
|
||||||
public function appendOutput(string $string): ViewInterface;
|
public function appendOutput(string $string): self;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current output as a string. Does not
|
* Get the current output as a string. Does not
|
||||||
|
@ -63,6 +63,13 @@ class HttpViewTest extends Ion_TestCase {
|
|||||||
$this->assertEquals(404, $view->response->getStatusCode());
|
$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()
|
public function testSendDoubleRenderException()
|
||||||
{
|
{
|
||||||
$this->expectException(DoubleRenderException::class);
|
$this->expectException(DoubleRenderException::class);
|
||||||
|
Loading…
Reference in New Issue
Block a user