lib: Introduce Response::setRerenderLayout()

Instead of handling response headers based on flags in our controllers, this should happen in the request for usage w/o controllers.

refs #9660
This commit is contained in:
Eric Lippmann 2015-07-29 14:39:45 +02:00
parent 91720810cc
commit aaae7e03b4
1 changed files with 49 additions and 0 deletions

View File

@ -15,6 +15,13 @@ class Response extends Zend_Controller_Response_Http
*/ */
protected $request; protected $request;
/**
* Whether to send the rerender layout header on XHR
*
* @var bool
*/
protected $rerenderLayout = false;
/** /**
* Get the request * Get the request
* *
@ -28,6 +35,39 @@ class Response extends Zend_Controller_Response_Http
return $this->request; return $this->request;
} }
/**
* Get whether to send the rerender layout header on XHR
*
* @return bool
*/
public function getRerenderLayout()
{
return $this->rerenderLayout;
}
/**
* Get whether to send the rerender layout header on XHR
*
* @param bool $rerenderLayout
*
* @return $this
*/
public function setRerenderLayout($rerenderLayout = true)
{
$this->rerenderLayout = (bool) $rerenderLayout;
return $this;
}
/**
* Prepare the request before sending
*/
protected function prepare()
{
if ($this->getRequest()->isXmlHttpRequest() && $this->getRerenderLayout()) {
$this->setHeader('X-Icinga-Rerender-Layout', 'yes');
}
}
/** /**
* Redirect to the given URL and exit immediately * Redirect to the given URL and exit immediately
* *
@ -54,4 +94,13 @@ class Response extends Zend_Controller_Response_Http
$this->sendHeaders(); $this->sendHeaders();
exit; exit;
} }
/**
* {@inheritdoc}
*/
public function sendHeaders()
{
$this->prepare();
return parent::sendHeaders();
}
} }