/** * Compiles the node * * @param Context $context The context * @param array|null $arguments Array of arguments * @param boolean|null $important Important flag * @return Node * @throws CompilerException */ public function compile(Context $context, $arguments = null, $important = null) { $name = $this->name; if (strpos($name, '@@') === 0) { $v = new VariableNode(substr($name, 1), $this->index, $this->currentFileInfo); $name = '@' . $v->compile($context)->value; } if ($this->evaluating) { throw new CompilerException(sprintf('Recursive variable definition for %s', $name), $this->index, $this->currentFileInfo); } $this->evaluating = true; $variable = null; // variables from the API take precedence if ($context->customVariables && ($v = $context->customVariables->variable($name))) { $variable = $v->value->compile($context); } else { // search for the variable foreach ($context->frames as $frame) { /* @var $frame RulesetNode */ if ($v = $frame->variable($name)) { /* @var $v RuleNode */ if ($v->important) { $importantScope =& $context->importantScope[count($context->importantScope) - 1]; $importantScope['important'] = $v->important; } $variable = $v->value->compile($context); break; } } } if ($variable) { $this->evaluating = false; return $variable; } else { throw new CompilerException(sprintf('variable %s is undefined', $name), $this->index, $this->currentFileInfo); } }
/** * Compiles the node * * @param Context $context The context * @param array|null $arguments Array of arguments * @param boolean|null $important Important flag * @return Node */ public function compile(Context $context, $arguments = null, $important = null) { $variable = new VariableNode($this->variable); $detachedRuleset = $variable->compile($context); return $detachedRuleset->callCompile($context); }