Example #1
0
 /**
  * Compiles the node
  *
  * @param Context $context The context
  * @param array|null $arguments Array of arguments
  * @param boolean|null $important Important flag
  * @return ParenNode|ExpressionNode|Node
  */
 public function compile(Context $context, $arguments = null, $important = null)
 {
     $inParenthesis = $this->parens && !$this->parensInOp;
     $doubleParen = false;
     if ($inParenthesis) {
         $context->inParenthesis();
     }
     $count = count($this->value);
     if ($count > 1) {
         $compiled = [];
         foreach ($this->value as $v) {
             /* @var $v Node */
             $compiled[] = $v->compile($context);
         }
         $return = new ExpressionNode($compiled);
     } elseif ($count === 1) {
         if (property_exists($this->value[0], 'parens') && $this->value[0]->parens && property_exists($this->value[0], 'parensInOp') && !$this->value[0]->parensInOp) {
             $doubleParen = true;
         }
         $return = $this->value[0]->compile($context);
     } else {
         $return = $this;
     }
     if ($inParenthesis) {
         $context->outOfParenthesis();
     }
     if ($this->parens && $this->parensInOp && !$context->isMathOn() && !$doubleParen) {
         $return = new ParenNode($return);
     }
     return $return;
 }