本文整理汇总了PHP中Dwoo_Compiler::getAutoEscape方法的典型用法代码示例。如果您正苦于以下问题:PHP Dwoo_Compiler::getAutoEscape方法的具体用法?PHP Dwoo_Compiler::getAutoEscape怎么用?PHP Dwoo_Compiler::getAutoEscape使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dwoo_Compiler
的用法示例。
在下文中一共展示了Dwoo_Compiler::getAutoEscape方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preProcessing
public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
{
$params = $compiler->getCompiledParams($params);
switch (strtolower(trim((string) $params['enabled'], '"\''))) {
case 'on':
case 'true':
case 'enabled':
case 'enable':
case '1':
$enable = true;
break;
case 'off':
case 'false':
case 'disabled':
case 'disable':
case '0':
$enable = false;
break;
default:
throw new Dwoo_Compilation_Exception($compiler, 'Auto_Escape : Invalid parameter (' . $params['enabled'] . '), valid parameters are "enable"/true or "disable"/false');
}
self::$stack[] = $compiler->getAutoEscape();
$compiler->setAutoEscape($enable);
return '';
}
示例2: paramsToAttributes
/**
* utility function that converts an array of compiled parameters (or rest array) to a string of xml/html tag attributes
*
* this is to be used in preProcessing or postProcessing functions, example :
* $p = $compiler->getCompiledParams($params);
* // get only the rest array as attributes
* $attributes = Dwoo_Plugin::paramsToAttributes($p['*']);
* // get all the parameters as attributes (if there is a rest array, it will be included)
* $attributes = Dwoo_Plugin::paramsToAttributes($p);
*
* @param array $params an array of attributeName=>value items that will be compiled to be ready for inclusion in a php string
* @param string $delim the string delimiter you want to use (defaults to ')
* @param Dwoo_Compiler $compiler the compiler instance (optional for BC, but recommended to pass it for proper escaping behavior)
* @return string
*/
public static function paramsToAttributes(array $params, $delim = '\'', Dwoo_Compiler $compiler = null)
{
if (isset($params['*'])) {
$params = array_merge($params, $params['*']);
unset($params['*']);
}
$out = '';
foreach ($params as $attr => $val) {
$out .= ' ' . $attr . '=';
if (trim($val, '"\'') == '' || $val == 'null') {
$out .= str_replace($delim, '\\' . $delim, '""');
} elseif (substr($val, 0, 1) === $delim && substr($val, -1) === $delim) {
$out .= str_replace($delim, '\\' . $delim, '"' . substr($val, 1, -1) . '"');
} else {
if (!$compiler) {
// disable double encoding since it can not be determined if it was encoded
$escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset, false) : $tmp2).';
} elseif (!$compiler->getAutoEscape() || false === strpos($val, 'isset($this->scope')) {
// escape if auto escaping is disabled, or there was no variable in the string
$escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset) : $tmp2).';
} else {
// print as is
$escapedVal = '.' . $val . '.';
}
$out .= str_replace($delim, '\\' . $delim, '"') . $delim . $escapedVal . $delim . str_replace($delim, '\\' . $delim, '"');
}
}
return ltrim($out);
}
示例3: testAutoEscapeWithFunctionCall
public function testAutoEscapeWithFunctionCall()
{
$cmp = new Dwoo_Compiler();
$cmp->setAutoEscape(true);
$this->assertEquals(true, $cmp->getAutoEscape());
$tpl = new Dwoo_Template_String('{upper $foo}{upper $foo|safe}');
$tpl->forceCompilation();
$this->assertEquals("A<B>CA<B>C", $this->dwoo->get($tpl, array('foo' => 'a<b>c'), $cmp));
}
示例4: paramsToAttributes
public static function paramsToAttributes(array $params, $delim = '\'', Dwoo_Compiler $compiler = null)
{
if (isset($params['*'])) {
$params = array_merge($params, $params['*']);
unset($params['*']);
}
$out = '';
foreach ($params as $attr => $val) {
$out .= ' ' . $attr . '=';
if (trim($val, '"\'') == '' || $val == 'null') {
$out .= str_replace($delim, '\\' . $delim, '""');
} elseif (substr($val, 0, 1) === $delim && substr($val, -1) === $delim) {
$out .= str_replace($delim, '\\' . $delim, '"' . substr($val, 1, -1) . '"');
} else {
if (!$compiler) {
$escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset, false) : $tmp2).';
} elseif (!$compiler->getAutoEscape() || false === strpos($val, 'isset($this->scope')) {
$escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset) : $tmp2).';
} else {
$escapedVal = '.' . $val . '.';
}
$out .= str_replace($delim, '\\' . $delim, '"') . $delim . $escapedVal . $delim . str_replace($delim, '\\' . $delim, '"');
}
}
return ltrim($out);
}