You are here

public function Twig_Node_Expression_Filter_Default::__construct in Translation template extractor 6.3

Same name and namespace in other branches
  1. 7.3 vendor/Twig/Node/Expression/Filter/Default.php \Twig_Node_Expression_Filter_Default::__construct()

Constructor.

The nodes are automatically made available as properties ($this->node). The attributes are automatically made available as array items ($this['name']).

Parameters

array $nodes An array of named nodes:

array $attributes An array of attributes (should not be nodes):

int $lineno The line number:

string $tag The tag name associated with the Node:

Overrides Twig_Node_Expression_Filter::__construct

File

vendor/Twig/Node/Expression/Filter/Default.php, line 23

Class

Twig_Node_Expression_Filter_Default
Returns the value or the default value when it is undefined or empty.

Code

public function __construct(Twig_NodeInterface $node, Twig_Node_Expression_Constant $filterName, Twig_NodeInterface $arguments, $lineno, $tag = null) {
  $default = new Twig_Node_Expression_Filter($node, new Twig_Node_Expression_Constant('default', $node
    ->getLine()), $arguments, $node
    ->getLine());
  if ('default' === $filterName
    ->getAttribute('value') && ($node instanceof Twig_Node_Expression_Name || $node instanceof Twig_Node_Expression_GetAttr)) {
    $test = new Twig_Node_Expression_Test_Defined(clone $node, 'defined', new Twig_Node(), $node
      ->getLine());
    $false = count($arguments) ? $arguments
      ->getNode(0) : new Twig_Node_Expression_Constant('', $node
      ->getLine());
    $node = new Twig_Node_Expression_Conditional($test, $default, $false, $node
      ->getLine());
  }
  else {
    $node = $default;
  }
  parent::__construct($node, $filterName, $arguments, $lineno, $tag);
}