本文整理汇总了PHP中Twig_Token::Text方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Token::Text方法的具体用法?PHP Twig_Token::Text怎么用?PHP Twig_Token::Text使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twig_Token
的用法示例。
在下文中一共展示了Twig_Token::Text方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: lexData
private function lexData()
{
$match = NULL;
// if no matches are left we return the rest of the template
// as simple text token
if (!preg_match('/(.*?)(\\{[%#]|\\$(?!\\$))/A', $this->code, $match, NULL, $this->cursor)) {
$rv = Twig_Token::Text(substr($this->code, $this->cursor), $this->lineno);
$this->cursor = $this->end;
return $rv;
}
$this->cursor += strlen($match[0]);
// update the lineno on the instance
$lineno = $this->lineno;
$this->lineno += substr_count($match[0], '\\n');
// push the template text first
$text = $match[1];
if (!empty($text)) {
$result = array(Twig_Token::Text($text, $lineno));
$lineno += substr_count($text, '\\n');
} else {
$result = array();
}
// block start token, let's return a token for that.
if (($token = $match[2]) !== '$') {
// if our section is a comment, just return the text
if ($token[1] == '#') {
if (!preg_match('/.*?#\\}/A', $this->code, $match, NULL, $this->cursor)) {
throw new Twig_SyntaxError('unclosed comment', $this->lineno);
}
$this->cursor += strlen($match[0]);
$this->lineno += substr_count($match[0], '\\n');
return $result;
}
$result[] = new Twig_Token(Twig_Token::BLOCK_START_TYPE, '', $lineno);
$this->position = self::POSITION_BLOCK;
} else {
if (isset($this->code[$this->cursor]) && $this->code[$this->cursor] == '{') {
$this->cursor++;
$result[] = new Twig_Token(Twig_Token::VAR_START_TYPE, '', $lineno);
$this->position = self::POSITION_VAR;
} else {
if (preg_match(self::REGEX_NAME, $this->code, $match, NULL, $this->cursor)) {
$result[] = new Twig_Token(Twig_Token::VAR_START_TYPE, '', $lineno);
$result[] = Twig_Token::Name($match[0], $lineno);
$this->cursor += strlen($match[0]);
// allow attribute lookup
while (isset($this->code[$this->cursor]) && $this->code[$this->cursor] === '.') {
++$this->cursor;
$result[] = Twig_Token::Operator('.', $this->lineno);
if (preg_match(self::REGEX_NAME, $this->code, $match, NULL, $this->cursor)) {
$this->cursor += strlen($match[0]);
$result[] = Twig_Token::Name($match[0], $this->lineno);
} else {
if (preg_match(self::REGEX_NUMBER, $this->code, $match, NULL, $this->cursor)) {
$this->cursor += strlen($match[0]);
$result[] = Twig_Token::Number($match[0], $this->lineno);
} else {
--$this->cursor;
break;
}
}
}
$result[] = new Twig_Token(Twig_Token::VAR_END_TYPE, '', $lineno);
}
}
}
return $result;
}