Ejemplo n.º 1
0
 protected function build(Board $board, $depth = 0)
 {
     $weight = $this->getPrecedence();
     $indent = $board->indent($depth);
     $index = 0;
     /* @var $child Node */
     foreach ($this->getChildren() as $child) {
         // Prep
         $wrap = $child->getPrecedence() < $weight;
         // Indent
         if ($this->isBlock()) {
             $index && $board->write("\n");
             $board->write($indent);
         }
         // Operator
         if ($index) {
             $board->write($child->isBlock() && !$wrap ? '' : ' ');
         }
         // Child:
         $wrap && $board->write("(");
         $child->isBlock() && $board->write("\n");
         $child->build($board, $depth + 1);
         $wrap && $board->write(")");
         // ===
         $index++;
     }
 }
Ejemplo n.º 2
0
 /**
  * @param Board $board
  * @param int $depth
  */
 protected function build(Board $board, $depth)
 {
     $weight = $this->getPrecedence();
     $indent = $board->indent($depth);
     $index = 0;
     /* @var $child Node */
     foreach ($this->getChildren() as $child) {
         // Prep
         $wrap = $child->getPrecedence() <= $weight;
         // Operator
         if ($index) {
             $board->write(',');
             if ($this->isBlock()) {
                 $board->write("\n");
                 (!$child->isBlock() || $wrap) && $board->write($indent);
             } else {
                 $board->write(" ");
             }
         } else {
             $this->isBlock() && $board->write($indent);
         }
         // Child:
         if ($wrap) {
             $board->write("(");
             $child->isBlock() && $board->write("\n");
         }
         $child->build($board, $depth + 1);
         $wrap && $board->write(")");
         // ===
         $index++;
     }
 }
Ejemplo n.º 3
0
 protected function build(Board $board, $depth)
 {
     $index = 0;
     $indent = $board->indent($depth);
     //
     foreach ($this->components as $compo) {
         if ($index > 0) {
             $board->write("\n");
         }
         $board->write($indent);
         if ($compo['type']) {
             $board->write($compo['type'])->write(' ');
         }
         $compo['ref']->build($board, $depth + 1);
         if ($compo['alias']) {
             $board->write(' AS ');
             $compo['alias']->build($board, $depth + 1);
         }
         if ($compo['cond']) {
             $board->write(' ON (');
             $compo['cond']->build($board, $depth + 1);
             $board->write(')');
         }
         $index++;
     }
 }
Ejemplo n.º 4
0
 /**
  *
  * @param string $part
  * @param Node|null $node
  * @param Board $board
  * @param int $depth
  */
 protected function buildPart($part, $node, $board, $depth)
 {
     if ($node) {
         $indent = $board->indent($depth);
         $board->write($indent)->write($part);
         $board->write($node->isBlock() ? "\n" : ' ');
         $node->build($board, $depth + 1);
         $board->write("\n");
     }
 }
Ejemplo n.º 5
0
 /**
  * @param Board $board
  * @param int $depth
  */
 protected function build(Board $board, $depth)
 {
     $expr = $this->getExpr();
     $alias = $this->getAlias();
     $wrap = $expr->getPrecedence() < $this->getPrecedence();
     $indent = $board->indent($depth);
     $block = $this->isBlock();
     // Column:
     $block && $board->write($indent);
     $wrap && $board->write('(');
     $expr->isBlock() && $board->write("\n");
     $expr->build($board, $depth + 1);
     $block && $board->write($indent);
     $wrap && $board->write(')');
     // Alias:
     if ($alias) {
         $board->write(' AS ');
         $alias->build($board, $depth + 1);
     }
 }