本文整理汇总了PHP中Twig_Token::test方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Token::test方法的具体用法?PHP Twig_Token::test怎么用?PHP Twig_Token::test使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twig_Token
的用法示例。
在下文中一共展示了Twig_Token::test方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
public function parse(\Twig_Token $token)
{
$lineno = $token->getLine();
$stream = $this->parser->getStream();
// 'svg'
$name = $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
// %} (from {% stamp %})
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
$aboveDumps = [];
while (true) {
// everything above {% stamp_dump %}
$aboveDumps[] = $this->parser->subparse(function (\Twig_Token $token) {
return $token->test('stamp_dump');
});
// allow nested {% stamp %} usage using distinct names
$dumpName = $stream->next() && $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
if ($dumpName == $name) {
break;
}
}
// %} (from {% stamp_dump %})
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
// everything below {% stamp_dump %}
$belowDump = $this->parser->subparse(function (\Twig_Token $token) {
return $token->test('endstamp');
});
// %} (from {% endstamp %})
$stream->next() && $stream->expect(\Twig_Token::BLOCK_END_TYPE);
return new StampNode($name, $aboveDumps, $belowDump, $lineno, $this->getTag());
}
示例2: parse
/**
* {@inheritdoc}
*/
public function parse(\Twig_Token $token)
{
$lineno = $token->getLine();
$stream = $this->parser->getStream();
$name = $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
$options = [];
while (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
if (!$stream->test(\Twig_Token::NAME_TYPE)) {
$this->throwSyntaxError($stream);
}
$key = $stream->getCurrent()->getValue();
$stream->next();
if (!$stream->test(\Twig_Token::OPERATOR_TYPE, '=')) {
$options[$key] = true;
continue;
}
$stream->next();
if (!$this->testOptionValue($stream)) {
$this->throwSyntaxError($stream);
}
$options[$key] = $this->getOptionValue($stream);
$stream->next();
}
$stream->next();
$body = $this->parser->subparse(function (\Twig_Token $token) {
return $token->test(['endcontenteditable']);
}, true);
if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
throw new \Twig_Error_Syntax('A text inside a contenteditable tag must be a simple text.', $body->getLine(), $stream->getFilename());
}
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
return new ContentEditableNode(['body' => $body], ['name' => $name, 'options' => $options], $lineno, $this->getTag());
}
示例3: parse
/**
* @see Twig_TokenParserInterface::parse()
*/
public function parse(\Twig_Token $token)
{
$this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
$body = $this->parser->subparse(function (\Twig_Token $token) {
return $token->test('endmarkdown');
}, true);
$this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
return new TwigMarkdownNode($body, $token->getLine(), $this->getTag());
}
示例4: parse
public function parse(\Twig_Token $token)
{
$lineno = $token->getLine();
$stream = $this->parser->getStream();
// key, item in items
$targets = $this->parser->getExpressionParser()->parseAssignmentExpression();
$stream->expect(\Twig_Token::OPERATOR_TYPE, 'in');
$seq = $this->parser->getExpressionParser()->parseExpression();
// as treeA
$as = 'default';
if ($stream->nextIf(\Twig_Token::NAME_TYPE, 'as')) {
$as = $stream->expect(\Twig_Token::NAME_TYPE)->getValue();
}
// %}
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
$data = array();
while (true) {
// backing up tag content
$data[] = array('type' => 'body', 'node' => $this->parser->subparse(function (\Twig_Token $token) {
return $token->test(array('subtree', 'endtree'));
}));
// {% subtree
if ($stream->next()->getValue() == 'subtree') {
// item
$child = $this->parser->getExpressionParser()->parseExpression();
// with treeA
$with = $as;
if ($stream->nextIf(\Twig_Token::NAME_TYPE, 'with')) {
$with = $stream->expect(\Twig_Token::NAME_TYPE)->getValue();
}
// %}
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
// backing up subtree details
$data[] = array('type' => 'subtree', 'with' => $with, 'child' => $child);
// {% endtree
} else {
// %}
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
break;
}
}
// key, item
if (count($targets) > 1) {
$keyTarget = $targets->getNode(0);
$keyTarget = new \Twig_Node_Expression_AssignName($keyTarget->getAttribute('name'), $keyTarget->getLine());
$valueTarget = $targets->getNode(1);
$valueTarget = new \Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getLine());
// (implicit _key,) item
} else {
$keyTarget = new \Twig_Node_Expression_AssignName('_key', $lineno);
$valueTarget = $targets->getNode(0);
$valueTarget = new \Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getLine());
}
return new TreeNode($keyTarget, $valueTarget, $seq, $as, $data, $lineno, $this->getTag());
}
示例5: parse
/**
* Разбирает выражение
*
* @param TwigToken $token Токен.
*
* @return WhileNode
*/
public function parse(TwigToken $token)
{
$lineNumber = $token->getLine();
$condition = $this->parser->getExpressionParser()->parseExpression();
$stream = $this->parser->getStream();
$stream->expect(TwigToken::BLOCK_END_TYPE);
$callback = function (TwigToken $token) {
return $token->test(['endwhile']);
};
$body = $this->parser->subparse($callback, true);
$stream->expect(TwigToken::BLOCK_END_TYPE);
return new WhileNode($condition, $body, $lineNumber, $this->getTag());
}
示例6: testEndTag
public function testEndTag(\Twig_Token $token)
{
return $token->test(array('end' . $this->getTag()));
}
示例7: decideForEnd
public function decideForEnd(Twig_Token $token)
{
return $token->test('endfor');
}
示例8: decideBlockEnd
public function decideBlockEnd(Twig_Token $token)
{
return $token->test('endautoescape');
}
示例9: decideCacheEnd
/**
* @param \Twig_Token $token
*
* @return bool
*/
public function decideCacheEnd(\Twig_Token $token)
{
return $token->test('endcache');
}
示例10: decideNavEnd
/**
* @param \Twig_Token $token
*
* @return bool
*/
public function decideNavEnd(\Twig_Token $token)
{
return $token->test('endnav');
}
示例11: decideMarkdownEnd
public function decideMarkdownEnd(Twig_Token $token)
{
return $token->test('endmarkdown');
}
示例12: decideHmacEnd
/**
* @param Twig_Token $token
* @return bool
*/
public function decideHmacEnd(\Twig_Token $token)
{
return $token->test('endhmac');
}
示例13: decideWithEnd
public function decideWithEnd(Twig_Token $token)
{
return $token->test('endwith');
}
示例14: decideStopwatchEnd
public function decideStopwatchEnd(\Twig_Token $token)
{
return $token->test('endstopwatch');
}
示例15: decideIfEnd
public function decideIfEnd(Twig_Token $token)
{
return $token->test(array('endif'));
}