public function escapePass(MacroTokens $tokens)
{
$tokens = clone $tokens;
list($contentType, $context) = $this->context;
switch ($contentType) {
case Compiler::CONTENT_XHTML:
case Compiler::CONTENT_HTML:
switch ($context) {
case Compiler::CONTEXT_HTML_TEXT:
return $tokens->prepend('LR\\Filters::escapeHtmlText(')->append(')');
case Compiler::CONTEXT_HTML_TAG:
case Compiler::CONTEXT_HTML_ATTRIBUTE_UNQUOTED_URL:
return $tokens->prepend('LR\\Filters::escapeHtmlAttrUnquoted(')->append(')');
case Compiler::CONTEXT_HTML_ATTRIBUTE:
case Compiler::CONTEXT_HTML_ATTRIBUTE_URL:
return $tokens->prepend('LR\\Filters::escapeHtmlAttr(')->append(')');
case Compiler::CONTEXT_HTML_ATTRIBUTE_JS:
return $tokens->prepend('LR\\Filters::escapeHtmlAttr(LR\\Filters::escapeJs(')->append('))');
case Compiler::CONTEXT_HTML_ATTRIBUTE_CSS:
return $tokens->prepend('LR\\Filters::escapeHtmlAttr(LR\\Filters::escapeCss(')->append('))');
case Compiler::CONTEXT_HTML_COMMENT:
return $tokens->prepend('LR\\Filters::escapeHtmlComment(')->append(')');
case Compiler::CONTEXT_HTML_BOGUS_COMMENT:
return $tokens->prepend('LR\\Filters::escapeHtml(')->append(')');
case Compiler::CONTEXT_HTML_JS:
case Compiler::CONTEXT_HTML_CSS:
return $tokens->prepend('LR\\Filters::escape' . ucfirst($context) . '(')->append(')');
default:
throw new CompileException("Unknown context {$contentType}, {$context}.");
}
case Compiler::CONTENT_XML:
switch ($context) {
case Compiler::CONTEXT_XML_TEXT:
case Compiler::CONTEXT_XML_ATTRIBUTE:
case Compiler::CONTEXT_XML_BOGUS_COMMENT:
return $tokens->prepend('LR\\Filters::escapeXml(')->append(')');
case Compiler::CONTEXT_XML_COMMENT:
return $tokens->prepend('LR\\Filters::escapeHtmlComment(')->append(')');
case Compiler::CONTEXT_XML_TAG:
return $tokens->prepend('LR\\Filters::escapeXmlAttrUnquoted(')->append(')');
default:
throw new CompileException("Unknown context {$contentType}, {$context}.");
}
case Compiler::CONTENT_JS:
case Compiler::CONTENT_CSS:
case Compiler::CONTENT_ICAL:
return $tokens->prepend('LR\\Filters::escape' . ucfirst($contentType) . '(')->append(')');
case Compiler::CONTENT_TEXT:
return $tokens;
case NULL:
return $tokens->prepend('call_user_func($this->filters->escape, ')->append(')');
default:
throw new CompileException("Unknown context {$contentType}.");
}
}