本文整理汇总了PHP中Twig_Token::getTypeAsString方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Token::getTypeAsString方法的具体用法?PHP Twig_Token::getTypeAsString怎么用?PHP Twig_Token::getTypeAsString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twig_Token
的用法示例。
在下文中一共展示了Twig_Token::getTypeAsString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: expect
/**
* Expects a token (like $token->test()) and returns it or throw a syntax error.
*/
public function expect($primary, $secondary = null)
{
$token = $this->current;
if (!$token->test($primary, $secondary)) {
throw new Twig_SyntaxError(sprintf('Unexpected token %s (%s expected, value: %s)', Twig_Token::getTypeAsString($token->getType()), Twig_Token::getTypeAsString($primary), $token->getValue()), $this->current->getLine());
}
$this->next();
return $token;
}
示例2: parsePrimaryExpression
public function parsePrimaryExpression($assignment = false)
{
$token = $this->parser->getCurrentToken();
switch ($token->getType()) {
case Twig_Token::NAME_TYPE:
$this->parser->getStream()->next();
switch ($token->getValue()) {
case 'true':
$node = new Twig_Node_Expression_Constant(true, $token->getLine());
break;
case 'false':
$node = new Twig_Node_Expression_Constant(false, $token->getLine());
break;
case 'none':
$node = new Twig_Node_Expression_Constant(null, $token->getLine());
break;
default:
$cls = $assignment ? 'Twig_Node_Expression_AssignName' : 'Twig_Node_Expression_Name';
$node = new $cls($token->getValue(), $token->getLine());
}
break;
case Twig_Token::NUMBER_TYPE:
case Twig_Token::STRING_TYPE:
$this->parser->getStream()->next();
$node = new Twig_Node_Expression_Constant($token->getValue(), $token->getLine());
break;
default:
if ($token->test(Twig_Token::OPERATOR_TYPE, '[')) {
$node = $this->parseArrayExpression();
} elseif ($token->test(Twig_Token::OPERATOR_TYPE, '(')) {
$this->parser->getStream()->next();
$node = $this->parseExpression();
$this->parser->getStream()->expect(Twig_Token::OPERATOR_TYPE, ')');
} else {
throw new Twig_SyntaxError(sprintf('Unexpected token "%s" of value "%s"', Twig_Token::getTypeAsString($token->getType()), $token->getValue()), $token->getLine());
}
}
if (!$assignment) {
$node = $this->parsePostfixExpression($node);
}
return $node;
}
示例3: expect
/**
* Expects a token (like $token->test()) and returns it or throw a syntax error.
*/
public function expect($primary, $secondary = null)
{
$token = $this->current;
if (!$token->test($primary, $secondary)) {
throw new Twig_Error_Syntax(sprintf('Unexpected token "%s" of value "%s" ("%s" expected%s)', Twig_Token::getTypeAsString($token->getType()), $token->getValue(), Twig_Token::getTypeAsString($primary), $secondary ? sprintf(' with value "%s"', $secondary) : ''), $this->current->getLine());
}
$this->next();
return $token;
}
示例4: parseHashExpression
public function parseHashExpression()
{
$stream = $this->parser->getStream();
$stream->expect(Twig_Token::PUNCTUATION_TYPE, '{', 'A hash element was expected');
$elements = array();
while (!$stream->test(Twig_Token::PUNCTUATION_TYPE, '}')) {
if (!empty($elements)) {
$stream->expect(Twig_Token::PUNCTUATION_TYPE, ',', 'A hash value must be followed by a comma (,)');
// trailing ,?
if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '}')) {
break;
}
}
if (!$stream->test(Twig_Token::STRING_TYPE) && !$stream->test(Twig_Token::NUMBER_TYPE)) {
throw new Twig_Error_Syntax(sprintf('A hash key must be a quoted string or a number (unexpected token "%s" of value "%s"', Twig_Token::getTypeAsString($stream->getCurrent()->getType()), $stream->getCurrent()->getValue()), $stream->getCurrent()->getLine());
}
$key = $stream->next()->getValue();
$stream->expect(Twig_Token::PUNCTUATION_TYPE, ':', 'A hash key must be followed by a colon (:)');
$elements[$key] = $this->parseExpression();
}
$stream->expect(Twig_Token::PUNCTUATION_TYPE, '}', 'An opened hash is not properly closed');
return new Twig_Node_Expression_Array($elements, $stream->getCurrent()->getLine());
}