Add global charset for Fenom

This commit is contained in:
bzick 2015-06-03 00:19:40 +03:00
parent c2751e069c
commit c6dbdfff95
3 changed files with 5 additions and 3 deletions

View File

@ -58,6 +58,8 @@ class Fenom
const ACCESSOR_VAR = 'Fenom\Accessor::parserVar';
const ACCESSOR_CALL = 'Fenom\Accessor::parserCall';
public static $charset = "UTF-8";
/**
* @var int[] of possible options, as associative array
* @see setOptions

View File

@ -58,13 +58,13 @@ class Modifier
* @param string $charset
* @return string
*/
public static function escape($text, $type = 'html', $charset = 'UTF-8')
public static function escape($text, $type = 'html', $charset = null)
{
switch (strtolower($type)) {
case "url":
return urlencode($text);
case "html";
return htmlspecialchars($text, ENT_COMPAT, $charset);
return htmlspecialchars($text, ENT_COMPAT, $charset ? $charset : \Fenom::$charset);
case "js":
return json_encode($text, 64 | 256); // JSON_UNESCAPED_SLASHES = 64, JSON_UNESCAPED_UNICODE = 256
default:

View File

@ -490,7 +490,7 @@ class Template extends Render
$escape = $this->_options & Fenom::AUTO_ESCAPE;
}
if ($escape) {
return "echo htmlspecialchars($data, ENT_COMPAT, 'UTF-8');";
return "echo htmlspecialchars($data, ENT_COMPAT, ".var_export(Fenom::$charset, true).");";
} else {
return "echo $data;";
}