diff --git a/src/Latte/Compiler/Compiler.php b/src/Latte/Compiler/Compiler.php index 3014fb805..fe0fccc00 100644 --- a/src/Latte/Compiler/Compiler.php +++ b/src/Latte/Compiler/Compiler.php @@ -42,7 +42,7 @@ class Compiler /** @var string */ private $contentType = self::CONTENT_HTML; - /** @var array [context, subcontext] */ + /** @var string|NULL */ private $context; /** @var mixed */ @@ -72,17 +72,23 @@ class Compiler /** @internal Context-aware escaping HTML contexts */ const - // for CONTENT_HTML, CONTENT_XHTML - CONTEXT_HTML_TAG = 'tag', - CONTEXT_HTML_ATTRIBUTE = 'attr', - CONTEXT_HTML_ATTRIBUTE_URL = 'attrurl', - CONTEXT_HTML_COMMENT = 'comment', - CONTEXT_HTML_BOGUS_COMMENT = 'bogus', - CONTEXT_HTML_CSS = 'css', - CONTEXT_HTML_JS = 'js', - + CONTEXT_HTML_TEXT = NULL, + CONTEXT_HTML_TAG = 'Tag', + CONTEXT_HTML_ATTRIBUTE = 'Attr', + CONTEXT_HTML_ATTRIBUTE_JS = 'AttrJs', + CONTEXT_HTML_ATTRIBUTE_CSS = 'AttrCss', + CONTEXT_HTML_ATTRIBUTE_URL = 'AttrUrl', + CONTEXT_HTML_ATTRIBUTE_UNQUOTED_URL = 'AttrUnquotedUrl', + CONTEXT_HTML_COMMENT = 'Comment', + CONTEXT_HTML_BOGUS_COMMENT = 'Bogus', + CONTEXT_HTML_CSS = 'Css', + CONTEXT_HTML_JS = 'Js', + + CONTEXT_XML_TEXT = self::CONTEXT_HTML_TEXT, CONTEXT_XML_TAG = self::CONTEXT_HTML_TAG, - CONTEXT_XML_COMMENT = self::CONTEXT_HTML_COMMENT; + CONTEXT_XML_ATTRIBUTE = self::CONTEXT_HTML_ATTRIBUTE, + CONTEXT_XML_COMMENT = self::CONTEXT_HTML_COMMENT, + CONTEXT_XML_BOGUS_COMMENT = self::CONTEXT_HTML_BOGUS_COMMENT; /** @@ -203,9 +209,10 @@ public function getContentType() /** * @internal */ - public function setContext($context, $sub = NULL) + public function setContext($context) { - $this->context = [$context, $sub]; + trigger_error(__METHOD__ . ' is deprecated.', E_USER_DEPRECATED); + $this->context = $context; return $this; } @@ -301,7 +308,7 @@ public function expandTokens($s) private function processText(Token $token) { - if ($this->context[0] === self::CONTEXT_HTML_ATTRIBUTE && $this->lastAttrValue === '') { + if ($this->lastAttrValue === '' && Helpers::startsWith($this->context, self::CONTEXT_HTML_ATTRIBUTE)) { $this->lastAttrValue = $token->text; } $this->output .= $this->escape($token->text); @@ -310,7 +317,7 @@ private function processText(Token $token) private function processMacroTag(Token $token) { - if (in_array($this->context[0], [self::CONTEXT_HTML_ATTRIBUTE, self::CONTEXT_HTML_TAG], TRUE)) { + if ($this->context === self::CONTEXT_HTML_TAG || Helpers::startsWith($this->context, self::CONTEXT_HTML_ATTRIBUTE)) { $this->lastAttrValue = TRUE; } @@ -355,20 +362,20 @@ private function processHtmlTagBegin(Token $token) } $this->htmlNode->closing = TRUE; $this->htmlNode->endLine = $this->getLine(); - $this->setContext(NULL); + $this->context = self::CONTEXT_HTML_TEXT; } elseif ($token->text === '