Phundament-Components
[ class tree: Phundament-Components ] [ index: Phundament-Components ] [ all elements ]

Source for file LTidyHttpResponseAdapter.php

Documentation is available at LTidyHttpResponseAdapter.php

  1. <?php
  2.  
  3.  
  4. /**
  5.  * THttpResponseAdatper class
  6.  *
  7.  * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
  8.  * @link http://www.pradosoft.com/
  9.  * @copyright Copyright &copy; 2005 PradoSoft
  10.  * @license http://www.pradosoft.com/license/
  11.  * @version $Id$
  12.  * @package Phundament.Components
  13.  * @subpackage Adapter
  14.  */
  15.  
  16. /**
  17.  * THttpResponseAdapter class.
  18.  *
  19.  * THttpResponseAdapter allows the base http response class to change behaviour
  20.  * without change the class hierachy.
  21.  *
  22.  * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
  23.  * @version $Id$
  24.  * @package System.Util
  25.  * @subpackage Response
  26.  * @since 3.0
  27.  */
  28. class LTidyHttpResponseAdapter extends THttpResponseAdapter
  29. {
  30.     /**
  31.      * @var THttpResponse the response object the adapter is attached.
  32.      */
  33.     private $_response;
  34.  
  35.     /**
  36.      * Constructor. Attach a response to be adapted.
  37.      * @param THttpResponse the response object the adapter is to attach to.
  38.      */
  39.     public function __construct($response)
  40.     {
  41.         $this->_response$response;
  42.     }
  43.  
  44.     /**
  45.      * @return THttpResponse the response object adapted.
  46.      */
  47.     public function getResponse()
  48.     {
  49.         return $this->_response;
  50.     }
  51.  
  52.     /**
  53.      * This method is invoked when the response flushes the content and headers.
  54.      * Default implementation calls the attached response flushContent method.
  55.      */
  56.     public function flushContent()
  57.     {
  58.         // Tidy
  59.         if (TPropertyValue::ensureBoolean($this->Application->Parameters['TidyOutput']== true)
  60.         {
  61.             $bufferob_get_clean();
  62.             $configarray (
  63.                 'indent' => true,
  64.                 'output-xhtml' => true,
  65.                 'wrap' => 100
  66.             );
  67.             $tidynew tidy;
  68.             $tidy->parseString($buffer$config'utf8');
  69.             $tidy->cleanRepair();
  70.             echo $tidy;
  71.         }
  72.         else
  73.         {
  74.             #Prado::log($e->getMessage(), TLogger::WARNING, "Lithron.LTidyHttpResponseAdapter");
  75.             $this->_response->flushContent();
  76.         }
  77.  
  78.     }
  79.  
  80.     /**
  81.      * This method is invoked when the response is to redirect to another page.
  82.      * @param string new url to redirect to.
  83.      */
  84.     public function httpRedirect($url)
  85.     {
  86.         $this->_response->httpRedirect($url);
  87.     }
  88.  
  89.     /**
  90.      * This method is invoked when a new HtmlWriter needs to be created.
  91.      * Default implementation calls the attached response createNewHtmlWriter method.
  92.      * @param string type of the HTML writer to be created.
  93.      * @param ITextWriter the writer responsible for holding the content.
  94.      */
  95.     public function createNewHtmlWriter($type$writer)
  96.     {
  97.         return $this->_response->createNewHtmlWriter($type$writer);
  98.     }
  99. }
  100. ?>

Documentation generated on Sun, 25 Feb 2007 16:11:46 +0100 by phpDocumentor 1.3.1