You are here

public function Twig_Parser::setMacro in Translation template extractor 6.3

Same name and namespace in other branches
  1. 7.3 vendor/Twig/Parser.php \Twig_Parser::setMacro()

File

vendor/Twig/Parser.php, line 255

Class

Twig_Parser
Default parser implementation.

Code

public function setMacro($name, Twig_Node_Macro $node) {
  if (null === $this->reservedMacroNames) {
    $this->reservedMacroNames = array();
    $r = new ReflectionClass($this->env
      ->getBaseTemplateClass());
    foreach ($r
      ->getMethods() as $method) {
      $this->reservedMacroNames[] = $method
        ->getName();
    }
  }
  if (in_array($name, $this->reservedMacroNames)) {
    throw new Twig_Error_Syntax(sprintf('"%s" cannot be used as a macro name as it is a reserved keyword', $name), $node
      ->getLine(), $this
      ->getFilename());
  }
  $this->macros[$name] = $node;
}