summaryrefslogtreecommitdiff
path: root/framework/Web
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web')
-rw-r--r--framework/Web/THttpResponse.php68
-rw-r--r--framework/Web/UI/TTemplateManager.php4
2 files changed, 69 insertions, 3 deletions
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 <qiang.xue@gmail.com>
* @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.
@@ -119,6 +131,38 @@ class THttpResponse extends TModule implements ITextWriter
}
/**
+ * @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
*/
public function getBufferOutput()
@@ -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;
}
+
}
}