Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
70 lines (60 sloc) 1.74 KB
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/
namespace craft\web\twig\nodevisitors;
use craft\web\twig\nodes\GetAttrNode;
use Twig\Environment;
use Twig\Node\Expression\GetAttrExpression;
use Twig\Node\Node;
use Twig\NodeVisitor\NodeVisitorInterface;
/**
* GetAttrAdjuster swaps [[GetAttrExpression]] nodes with [[GetAttrNode]] nodes.
*
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
* @since 3.0
*/
class GetAttrAdjuster implements NodeVisitorInterface
{
/**
* @inheritdoc
*/
public function enterNode(Node $node, Environment $env)
{
// Make sure this is a GetAttrExpression (and not a subclass)
if (get_class($node) !== GetAttrExpression::class) {
return $node;
}
// Swap it with our custom GetAttrNode
$nodes = [
'node' => $node->getNode('node'),
'attribute' => $node->getNode('attribute')
];
if ($node->hasNode('arguments')) {
$nodes['arguments'] = $node->getNode('arguments');
}
$attributes = [
'type' => $node->getAttribute('type'),
'is_defined_test' => $node->getAttribute('is_defined_test'),
'ignore_strict_check' => $node->getAttribute('ignore_strict_check'),
'optimizable' => $node->getAttribute('optimizable'),
];
return new GetAttrNode($nodes, $attributes, $node->getTemplateLine(), $node->getNodeTag());
}
/**
* @inheritdoc
*/
public function leaveNode(Node $node, Environment $env)
{
return $node;
}
/**
* @inheritdoc
*/
public function getPriority()
{
return 0;
}
}
You can’t perform that action at this time.