From 333eedb6eea18fdfb7bc0890cce1c30e6d44d363 Mon Sep 17 00:00:00 2001 From: wei <> Date: Fri, 6 Jan 2006 22:21:07 +0000 Subject: --- framework/Web/THttpResponse.php | 68 +++++++++++++++++++++++++++++++++-- framework/Web/UI/TTemplateManager.php | 4 ++- 2 files changed, 69 insertions(+), 3 deletions(-) (limited to 'framework/Web') diff --git a/framework/Web/THttpResponse.php b/framework/Web/THttpResponse.php index ecaf59d0..cf44d19d 100644 --- a/framework/Web/THttpResponse.php +++ b/framework/Web/THttpResponse.php @@ -32,6 +32,9 @@ * where {@link getCacheExpire CacheExpire}, {@link getCacheControl CacheControl} * and {@link getBufferOutput BufferOutput} are configurable properties of THttpResponse. * + * When sending headers the Charset set in {@link TGlobalization::getCharset()} + * is use when Charset is null or empty in THttpResponse. + * * @author Qiang Xue * @version $Revision: $ $Date: $ * @package System.Web @@ -59,6 +62,15 @@ class THttpResponse extends TModule implements ITextWriter * @var string HTML writer type */ private $_htmlWriterType='System.Web.UI.THtmlWriter'; + /** + * @var string content type + */ + private $_contentType='text/html'; + + /** + * @var string character set, e.g. UTF-8 + */ + private $_charset; /** * Destructor. @@ -118,6 +130,38 @@ class THttpResponse extends TModule implements ITextWriter session_cache_limiter(TPropertyValue::ensureEnum($value,array('none','nocache','private','private_no_expire','public'))); } + /** + * @string content type, default is text/html + */ + public function setContentType($type) + { + $this->_contentType = $type; + } + + /** + * @return string current content type + */ + public function getContentType() + { + return $this->_contentType; + } + + /** + * @return string output charset. + */ + public function getCharset() + { + return $this->_charset; + } + + /** + * @param string output charset. + */ + public function setCharset($charset) + { + $this->_charset = $charset; + } + /** * @return boolean whether to enable output buffer */ @@ -226,13 +270,28 @@ class THttpResponse extends TModule implements ITextWriter } /** - * Outputs the buffered content. + * Outputs the buffered content, sends content-type and charset header. */ public function flush() { + $header = $this->getContentTypeHeader(); + $this->appendHeader($header); if($this->_bufferOutput) ob_flush(); - Prado::coreLog("Flushing output"); + Prado::coreLog("Flushing output $header"); + } + + /** + * @return string content type and charset header + */ + protected function getContentTypeHeader() + { + $app = $this->getApplication()->getGlobalization(); + $charset = $this->getCharset(); + if(empty($charset)) + $charset = !is_null($app) ? $app->getCharset() : 'UTF-8'; + $type = $this->getContentType(); + return "Content-Type: $type; charset=$charset"; } /** @@ -254,6 +313,11 @@ class THttpResponse extends TModule implements ITextWriter header($value); } + public function sendContentTypeHeader($type=null) + { + + } + /** * Writes a log message into error log. * This method is simple wrapper of PHP function error_log. diff --git a/framework/Web/UI/TTemplateManager.php b/framework/Web/UI/TTemplateManager.php index d5c5f0ba..df708e50 100644 --- a/framework/Web/UI/TTemplateManager.php +++ b/framework/Web/UI/TTemplateManager.php @@ -60,7 +60,7 @@ class TTemplateManager extends TModule public function getTemplateByClassName($className) { $class=new ReflectionClass($className); - $tplFile=dirname($class->getFileName()).'/'.$className.self::TEMPLATE_FILE_EXT; + $tplFile=dirname($class->getFileName()).'/'.$className.self::TEMPLATE_FILE_EXT; return $this->getTemplateByFileName($tplFile); } @@ -72,6 +72,7 @@ class TTemplateManager extends TModule { if(!is_null($fileName=$this->getLocalizedTemplate($fileName))) { + Prado::coreLog("Loading template $fileName"); if(($cache=$this->getApplication()->getCache())===null) return new TTemplate(file_get_contents($fileName),dirname($fileName),$fileName); else @@ -106,6 +107,7 @@ class TTemplateManager extends TModule if(($file=realpath($file))!==false && is_file($file)) return $file; } + } } -- cgit v1.2.3