* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 * @author Icinga Development Team * */ // {{{ICINGA_LICENSE_HEADER}}} class Zend_Controller_Action_Helper_DataFormatSwitch extends Zend_Controller_Action_Helper_ContextSwitch { protected $autoSerialization = true; public function setAutoJsonSerialization($value) { $this->autoSerialization = $value; $this->setAutoJsonSerialization($value); } public function __construct() { $this->setContexts( array( 'pdf' => array( 'suffix' => 'pdf', 'headers' => array('Content-Type' => 'application/pdf'), 'callbacks' => array( 'init' => 'removeStyles', 'post' => 'postPdfContext' ) ), 'json' => array( 'suffix' => 'json', 'headers' => array('Content-Type' => 'application/json'), 'callbacks' => array( 'init' => 'removeStyles', 'post' => 'postJsonContext' ) ), 'xml' => array( 'suffix' => 'xml', 'headers' => array('Content-Type' => 'application/xml'), 'callbacks' => array( 'init' => 'removeStyles', 'post' => 'postXmlContext' ) ) ) ); } private function postXmlContext() { if (!$this->autoSerialization) { return; } } private function postPdfContext() { if (!$this->autoSerialization) { return; } $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); $helper = new Zend_View_Helper_Pdf(); $this->getResponse()->setBody( $helper->pdf($viewRenderer->render()) ); } private function removeStyles() { if (!$this->getAutoJsonSerialization()) { return; } $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); $view = $viewRenderer->view; if ($view instanceof Zend_View_Interface) { $viewRenderer->setNoRender(true); } } }