Skip to content

Commit

Permalink
Merge pull request FriendsOfSymfony#298 from borisguery/headers-in-view
Browse files Browse the repository at this point in the history
Fix headers in View (FriendsOfSymfony#292)
  • Loading branch information
lsmith77 committed Sep 23, 2012
2 parents 20546ea + 29a47ea commit aa6ffae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
8 changes: 8 additions & 0 deletions Tests/View/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ public function testSetHeaders()
$this->assertEquals($expected, $view->getHeaders());
}

public function testHeadersInConstructorAreAssignedToResponseObject()
{
$headers = array('foo' => 'bar');
$expected = array('foo' => array('bar'), 'cache-control' => array('no-cache'));
$view = new View(null, null, $headers);
$this->assertEquals($expected, $view->getHeaders());
}

public function testSetStatusCode()
{
$view = new View();
Expand Down
11 changes: 3 additions & 8 deletions View/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ class View
*/
private $statusCode;

/**
* @var array
*/
private $headers;

/**
* @var string|TemplateReference
*/
Expand Down Expand Up @@ -112,8 +107,8 @@ public function __construct($data = null, $statusCode = null, array $headers = a
{
$this->data = $data;
$this->statusCode = $statusCode;
$this->headers = $headers;
$this->templateVar = 'data';
$this->getResponse()->headers->replace($headers);
}

/**
Expand Down Expand Up @@ -298,7 +293,7 @@ public function setRoute($route)
/**
* set the response
*
* @param Response $response
* @param Response $response
* @return View
*/
public function setResponse(Response $response)
Expand Down Expand Up @@ -335,7 +330,7 @@ public function getStatusCode()
*/
public function getHeaders()
{
return $this->response->headers->all();
return $this->getResponse()->headers->all();
}

/**
Expand Down

0 comments on commit aa6ffae

Please sign in to comment.