本文整理匯總了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;
}