本文整理汇总了PHP中Twig_NodeInterface::getIterator方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_NodeInterface::getIterator方法的具体用法?PHP Twig_NodeInterface::getIterator怎么用?PHP Twig_NodeInterface::getIterator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twig_NodeInterface
的用法示例。
在下文中一共展示了Twig_NodeInterface::getIterator方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: enterNode
/**
* Defined by Twig_NodeVisitorInterface
*
* Extracts messages from calls to the translate function.
*/
public function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env)
{
if ($node instanceof \Skeleton\I18n\Template\Twig\Extension\Node\Trans\Tigron) {
if ($node->getNodeTag() == 'trans') {
$this->extracted[] = $node->getNode('body')->getAttribute('value');
}
} elseif ($node instanceof \Twig_Node_Print) {
$n = $node->getNode('expr');
while ($n instanceof \Twig_Node_Expression_Filter) {
$filter = null;
if ($n->hasNode('filter')) {
$filter = $n->getNode('filter')->getAttribute('value');
}
$n = $n->getNode('node');
if ($n instanceof \Twig_Node_Expression_Constant and $filter == 'trans') {
$this->extracted[] = $n->getAttribute('value');
}
}
} elseif ($node instanceof \Twig_Node_Expression_Array) {
$data = $node->getIterator();
foreach ($data as $row) {
if ($row instanceof \Twig_Node_Expression_Filter) {
if ($row->hasNode('filter') and $row->getNode('filter')->getAttribute('value') == 'trans') {
$this->extracted[] = $row->getNode('node')->getAttribute('value');
}
}
}
}
return $node;
}
示例2: getDependencies
/**
* Parses module dependencies from Twig AST.
*
* @param JsCompiler $compiler
* @param \Twig_NodeInterface $node
*
* @return array of dependencies
*/
private function getDependencies(JsCompiler $compiler, \Twig_NodeInterface $node)
{
$dependencies = ['files' => [], 'functions' => []];
$stack = iterator_to_array($node->getIterator());
while (count($stack)) {
$subNode = array_shift($stack);
if (!$subNode instanceof \Twig_Node) {
continue;
}
if ($subNode instanceof \Twig_Node_Include || $subNode instanceof \Twig_Node_Import) {
$expr = $subNode->getNode('expr');
$env = $compiler->getEnvironment();
$path = $expr->getAttribute('value');
$source = $env->getLoader()->getSource($path);
$module = $env->parse($env->tokenize($source, $path));
$name = $compiler->getFunctionName($module);
array_push($dependencies['files'], $name . 'Template');
array_push($dependencies['functions'], $name);
} elseif ($subNode->count()) {
$stack = array_merge(iterator_to_array($subNode->getIterator()), $stack);
}
}
return $dependencies;
}