本文整理匯總了PHP中Twig_NodeInterface::setNode方法的典型用法代碼示例。如果您正苦於以下問題:PHP Twig_NodeInterface::setNode方法的具體用法?PHP Twig_NodeInterface::setNode怎麽用?PHP Twig_NodeInterface::setNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Twig_NodeInterface
的用法示例。
在下文中一共展示了Twig_NodeInterface::setNode方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: leaveNode
/**
* {@inheritdoc}
*/
public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
{
if ($node instanceof Twig_Node_Module) {
$varName = $this->getVarName();
$node->setNode('display_start', new Twig_Node(array(new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::TEMPLATE, $node->getAttribute('filename'), $varName), $node->getNode('display_start'))));
$node->setNode('display_end', new Twig_Node(array(new Twig_Profiler_Node_LeaveProfile($varName), $node->getNode('display_end'))));
} elseif ($node instanceof Twig_Node_Block) {
$varName = $this->getVarName();
$node->setNode('body', new Twig_Node_Body(array(new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::BLOCK, $node->getAttribute('name'), $varName), $node->getNode('body'), new Twig_Profiler_Node_LeaveProfile($varName))));
} elseif ($node instanceof Twig_Node_Macro) {
$varName = $this->getVarName();
$node->setNode('body', new Twig_Node_Body(array(new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::MACRO, $node->getAttribute('name'), $varName), $node->getNode('body'), new Twig_Profiler_Node_LeaveProfile($varName))));
}
return $node;
}
示例2: enterNode
/**
* {@inheritdoc}
*/
public function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env)
{
if ($node instanceof \Twig_Node_Block || $node instanceof \Twig_Node_Module) {
$this->scope = $this->scope->enter();
}
if ($node instanceof TransDefaultDomainNode) {
if ($node->getNode('expr') instanceof \Twig_Node_Expression_Constant) {
$this->scope->set('domain', $node->getNode('expr'));
return $node;
} else {
$var = $env->getParser()->getVarName();
$name = new \Twig_Node_Expression_AssignName($var, $node->getLine());
$this->scope->set('domain', new \Twig_Node_Expression_Name($var, $node->getLine()));
return new \Twig_Node_Set(false, new \Twig_Node(array($name)), new \Twig_Node(array($node->getNode('expr'))), $node->getLine());
}
}
if (!$this->scope->has('domain')) {
return $node;
}
if ($node instanceof \Twig_Node_Expression_Filter && in_array($node->getNode('filter')->getAttribute('value'), array('trans', 'transchoice'))) {
$ind = 'trans' === $node->getNode('filter')->getAttribute('value') ? 1 : 2;
$arguments = $node->getNode('arguments');
if (!$arguments->hasNode($ind)) {
if (!$arguments->hasNode($ind - 1)) {
$arguments->setNode($ind - 1, new \Twig_Node_Expression_Array(array(), $node->getLine()));
}
$arguments->setNode($ind, $this->scope->get('domain'));
}
} elseif ($node instanceof TransNode) {
if (null === $node->getNode('domain')) {
$node->setNode('domain', $this->scope->get('domain'));
}
}
return $node;
}
示例3: leaveNode
/**
* Called after child nodes are visited.
*
* @param Twig_NodeInterface $node The node to visit
* @param Twig_Environment $env The Twig environment instance
*
* @return Twig_NodeInterface The modified node
*/
public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
{
if ($node instanceof Twig_Node_Module) {
$this->inAModule = false;
$node->setNode('display_start', new Twig_Node(array(new Twig_Node_CheckSecurity($this->filters, $this->tags, $this->functions), $node->getNode('display_start'))));
}
return $node;
}
示例4: __construct
public function __construct(Twig_Node_Expression_AssignName $keyTarget, Twig_Node_Expression_AssignName $valueTarget, Twig_Node_Expression $seq, Twig_Node_Expression $ifexpr = null, Twig_NodeInterface $body, Twig_NodeInterface $else = null, $lineno, $tag = null)
{
$body->setNode('_for_loop', $this->loop = new Twig_Node_ForLoop($lineno, $tag));
if (null !== $ifexpr) {
$body = new Twig_Node_If(new Twig_Node(array($ifexpr, $body)), null, $lineno, $tag);
}
parent::__construct(array('key_target' => $keyTarget, 'value_target' => $valueTarget, 'seq' => $seq, 'body' => $body, 'else' => $else), array('with_loop' => true, 'ifexpr' => null !== $ifexpr), $lineno, $tag);
}
示例5: enterNode
public function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env)
{
if (!$this->enabled) {
return $node;
}
if ($node instanceof \Twig_Node_Expression_Filter && 'desc' === $node->getNode('filter')->getAttribute('value')) {
$transNode = $node->getNode('node');
while ($transNode instanceof \Twig_Node_Expression_Filter && 'trans' !== $transNode->getNode('filter')->getAttribute('value') && 'transchoice' !== $transNode->getNode('filter')->getAttribute('value')) {
$transNode = $transNode->getNode('node');
}
if (!$transNode instanceof \Twig_Node_Expression_Filter) {
throw new RuntimeException(sprintf('The "desc" filter must be applied after a "trans", or "transchoice" filter.'));
}
$wrappingNode = $node->getNode('node');
$testNode = clone $wrappingNode;
$defaultNode = $node->getNode('arguments')->getNode(0);
// if the |transchoice filter is used, delegate the call to the TranslationExtension
// so that we can catch a possible exception when the default translation has not yet
// been extracted
if ('transchoice' === $transNode->getNode('filter')->getAttribute('value')) {
$transchoiceArguments = new \Twig_Node_Expression_Array(array(), $transNode->getLine());
$transchoiceArguments->addElement($wrappingNode->getNode('node'));
$transchoiceArguments->addElement($defaultNode);
foreach ($wrappingNode->getNode('arguments') as $arg) {
$transchoiceArguments->addElement($arg);
}
$transchoiceNode = new \Twig_Node_Expression_MethodCall(new \Twig_Node_Expression_ExtensionReference('jms_translation', $transNode->getLine()), 'transchoiceWithDefault', $transchoiceArguments, $transNode->getLine());
$node->setNode('node', $transchoiceNode);
return $node;
}
// if the |trans filter has replacements parameters
// (e.g. |trans({'%foo%': 'bar'}))
if ($wrappingNode->getNode('arguments')->hasNode(0)) {
$lineno = $wrappingNode->getLine();
// remove the replacements from the test node
$testNode->setNode('arguments', clone $testNode->getNode('arguments'));
$testNode->getNode('arguments')->setNode(0, new \Twig_Node_Expression_Array(array(), $lineno));
// wrap the default node in a |replace filter
$defaultNode = new \Twig_Node_Expression_Filter(clone $node->getNode('arguments')->getNode(0), new \Twig_Node_Expression_Constant('replace', $lineno), new \Twig_Node(array(clone $wrappingNode->getNode('arguments')->getNode(0))), $lineno);
}
$condition = new \Twig_Node_Expression_Conditional(new \Twig_Node_Expression_Binary_Equal($testNode, $transNode->getNode('node'), $wrappingNode->getLine()), $defaultNode, clone $wrappingNode, $wrappingNode->getLine());
$node->setNode('node', $condition);
}
return $node;
}