You are here

public function Twig_ExpressionParser::getFunctionNode in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/twig/twig/lib/Twig/ExpressionParser.php \Twig_ExpressionParser::getFunctionNode()
1 call to Twig_ExpressionParser::getFunctionNode()
Twig_ExpressionParser::parsePrimaryExpression in vendor/twig/twig/lib/Twig/ExpressionParser.php

File

vendor/twig/twig/lib/Twig/ExpressionParser.php, line 314

Class

Twig_ExpressionParser
Parses expressions.

Code

public function getFunctionNode($name, $line) {
  switch ($name) {
    case 'parent':
      $this
        ->parseArguments();
      if (!count($this->parser
        ->getBlockStack())) {
        throw new Twig_Error_Syntax('Calling "parent" outside a block is forbidden.', $line, $this->parser
          ->getFilename());
      }
      if (!$this->parser
        ->getParent() && !$this->parser
        ->hasTraits()) {
        throw new Twig_Error_Syntax('Calling "parent" on a template that does not extend nor "use" another template is forbidden.', $line, $this->parser
          ->getFilename());
      }
      return new Twig_Node_Expression_Parent($this->parser
        ->peekBlockStack(), $line);
    case 'block':
      return new Twig_Node_Expression_BlockReference($this
        ->parseArguments()
        ->getNode(0), false, $line);
    case 'attribute':
      $args = $this
        ->parseArguments();
      if (count($args) < 2) {
        throw new Twig_Error_Syntax('The "attribute" function takes at least two arguments (the variable and the attributes).', $line, $this->parser
          ->getFilename());
      }
      return new Twig_Node_Expression_GetAttr($args
        ->getNode(0), $args
        ->getNode(1), count($args) > 2 ? $args
        ->getNode(2) : null, Twig_Template::ANY_CALL, $line);
    default:
      if (null !== ($alias = $this->parser
        ->getImportedSymbol('function', $name))) {
        $arguments = new Twig_Node_Expression_Array(array(), $line);
        foreach ($this
          ->parseArguments() as $n) {
          $arguments
            ->addElement($n);
        }
        $node = new Twig_Node_Expression_MethodCall($alias['node'], $alias['name'], $arguments, $line);
        $node
          ->setAttribute('safe', true);
        return $node;
      }
      $args = $this
        ->parseArguments(true);
      $class = $this
        ->getFunctionNodeClass($name, $line);
      return new $class($name, $args, $line);
  }
}