Implodes a list of WHERE clauses.

@param array $clauses

@return string
764930
protected function implodeClauses(array $clauses)
    {
        $str = '';
        $op = false;
        foreach ($clauses as $clause) {
            // an 'OR' token will change the operator used
            // when concatenating the next clause
            if ($clause == 'OR') {
                $op = ' OR ';
                continue;
            }

            if ($op && $str) {
                $str .= $op;
            }

            $str .= $clause;
            $op = ' AND ';
        }

        return $str;
    }
274264
protected function indentArray(array $elements) {
		return self::INDENTATION . \str_replace(PHP_EOL, PHP_EOL . self::INDENTATION, \implode(PHP_EOL, $elements));
	}
121841
protected function describeWhereFields($where)
    {
        return implode(', ', array_map(function ($v, $k) {
            return sprintf("%s='%s'", $k, $v);
        }, $where, array_keys($where)));
    }
806642
public function where($condition, $value = null, $append = false, $clause = "WHERE")
    {
        if (is_array($value)) {
            $condition = $this->formatWhereConditionWithMultipleTokens($condition, $value, $this->escapeValidator);
        } else {
            if ($value === null) {
                $condition = preg_replace("/=\s*\?/", "IS ?", $condition, 1);
                $value = 'NULL';
            } else if (is_bool($value)) {
                $value = $value ? 'TRUE' : 'FALSE';
            } else if (is_int($value) || is_float($value)) {
                // Preserve $value as is
            } else {
                $rid = $this->ridValidator->check($value, true);
                $value = $rid ? $rid : '"' . $this->escapeValidator->check($value, true) . '"';
            }

            $condition = str_replace("?", $value, $condition);
        }

        if (!$this->getTokenValue('Where')) {
            $clause = 'WHERE';
        }

        $this->setTokenValues('Where', array("{$clause} $condition"), $append, false, false);

        return $this;
    }
731723
static public function implodeStyles(array $styles)
    {
        $a = [];

        foreach ($styles as $p => $v) {
            $a[] = "$p:$v";
        }

        return implode(';', $a);
    }
400763
public function prepareWhere($wheres = null)
    {
        if (isset($wheres)) {
            if (!empty($wheres)) {
                $wheres = ' WHERE '.implode(' and ', array_values($wheres));
            } else {
                $wheres = '';
            }
        } else {
            $wheres = '';
        }

        return $wheres;
    }
454607
public function getWhereArray(array $clauses, array $options = [])
    {
        $query = $this->createBaseBuilder($options);

        $this->applyWhereArray($query, $clauses);

        return $query->get();
    }
222333
protected function _createPlaceholders($fields)
        {
            if (!empty($fields)) {
                $db_fields = [];

                foreach($fields as $key => $value) {
                    // Process expression fields directly into the query
                    if(Arrays::exists($key, $this->_expr_fields)) {
                        $db_fields[] = $value;
                    } else {
                        $db_fields[] = '?';
                    }
                }

                return implode(', ', $db_fields);
            }
        }
392388
protected function _createWhere(array $conditions) {
		$where = [];
		foreach ($conditions as $field => $value) {
			$where[] = $field . '=?';
		}
		$where = implode(' AND ', $where);
		if (!empty($where)) $where = 'WHERE ' . $where;
		return $where;
	}
637865
private static function clauseIsNested(array $clause): bool
    {
        $nestedLogicOp = $clause[0];
        $nestedClauses = $clause[1];

        return is_array($nestedClauses) && ($nestedLogicOp == LogicOp:: AND || $nestedLogicOp == LogicOp:: OR);
    }
1110324
public static function simplifyCNF(array $clauses)
    {
        $cloned_clauses = [];

        // avoid strict duplicates
        foreach ($clauses as $clause) {
            $unique_clause = clone $clause;
            foreach ($unique_clause->possibilities as $var_id => $possibilities) {
                if (count($possibilities)) {
                    $unique_clause->possibilities[$var_id] = array_unique($possibilities);
                }
            }
            $cloned_clauses[$clause->getHash()] = $unique_clause;
        }

        // remove impossible types
        foreach ($cloned_clauses as $clause_a) {
            if (count($clause_a->possibilities) !== 1 || count(array_values($clause_a->possibilities)[0]) !== 1) {
                continue;
            }

            if (!$clause_a->reconcilable || $clause_a->wedge) {
                continue;
            }

            $clause_var = array_keys($clause_a->possibilities)[0];
            $only_type = array_pop(array_values($clause_a->possibilities)[0]);
            $negated_clause_type = self::negateType($only_type);

            foreach ($cloned_clauses as $clause_b) {
                if ($clause_a === $clause_b || !$clause_b->reconcilable || $clause_b->wedge) {
                    continue;
                }

                if (isset($clause_b->possibilities[$clause_var]) &&
                    in_array($negated_clause_type, $clause_b->possibilities[$clause_var], true)
                ) {
                    $clause_b->possibilities[$clause_var] = array_filter(
                        $clause_b->possibilities[$clause_var],
                        /**
                         * @param string $possible_type
                         *
                         * @return bool
                         */
                        function ($possible_type) use ($negated_clause_type) {
                            return $possible_type !== $negated_clause_type;
                        }
                    );

                    if (count($clause_b->possibilities[$clause_var]) === 0) {
                        unset($clause_b->possibilities[$clause_var]);
                        $clause_b->impossibilities = null;
                    }
                }
            }
        }

        $deduped_clauses = [];

        // avoid strict duplicates
        foreach ($cloned_clauses as $clause) {
            $deduped_clauses[$clause->getHash()] = clone $clause;
        }

        $deduped_clauses = array_filter(
            $deduped_clauses,
            /**
             * @return bool
             */
            function (Clause $clause) {
                return count($clause->possibilities) || $clause->wedge;
            }
        );

        $simplified_clauses = [];

        foreach ($deduped_clauses as $clause_a) {
            $is_redundant = false;

            foreach ($deduped_clauses as $clause_b) {
                if ($clause_a === $clause_b
                    || !$clause_b->reconcilable
                    || $clause_b->wedge
                    || $clause_a->wedge
                ) {
                    continue;
                }

                if ($clause_a->contains($clause_b)) {
                    $is_redundant = true;
                    break;
                }
            }

            if (!$is_redundant) {
                $simplified_clauses[] = $clause_a;
            }
        }

        return $simplified_clauses;
    }
1349093
private function implodeArray(array $arr)
    {
        $values = [];

        foreach ($arr as $value) {
            if (is_array($value)) {
                $values[] = $this->implodeArray($value);
            } else {
                $values[] = $value;
            }
        }

        return "{" . implode(",", $values) . "}";
    }
240873
protected function formatWhere(array $where) : string {
    $where_clause = '';

    foreach ($where as $column => $value) {
      $logical_operator = null;

      if (is_numeric($column) && is_array($value)) {
        $where_clause .= "`{$value[0]}` {$value[1]} :where_{$value[0]}";
      } else if (is_numeric($column) && is_string($value)) {
        $logical_operator = $value;
      } else {
        $where_clause .= "`{$column}` = :where_{$column}";
      }

      $next_value = next($where);
      $next_key = key($where);

      if ( $next_value !== false && !is_null($next_key) && (!is_numeric($next_key) || !is_string($next_value)) )  {
        $logical_operator = $logical_operator ?? '&&';

        $where_clause .= " {$logical_operator} ";
      }
    }

    return $where_clause;
  }
1045773
public function where($clauses, $statements = null)
    {
        $this->settings['where'] = $clauses;

        if (is_array($this->settings['statements'])) {
            $this->settings['statements'] = array_merge(
                $this->settings['statements'],
                $statements
            );
        } else {
            $this->settings['statements'] = $statements;
        }

        return $this;
    }
109463
protected function enumValuesFromCheckClause($clause)
    {
        $segments = preg_split('/ +OR *\[/i', $clause);
        $constraints = array();
        foreach ($segments as $segment) {
            $bits = preg_split('/ *= */', $segment);
            for ($i = 1; $i < sizeof($bits); $i += 2) {
                array_unshift($constraints, substr(rtrim($bits[$i], ')'), 1, -1));
            }
        }
        return $constraints;
    }
1367680
protected function unfold(array $lines)
    {
        $string = implode(PHP_EOL, $lines);
        $string = preg_replace('/' . PHP_EOL . '[ \t]/', '', $string);
        $lines  = explode(PHP_EOL, $string);

        return $lines;
    }
589986
private function clauseConfig() {
    $config = array();
    $config[] = 'format:' . $this->getFormat();
    $config[] = 'start:' . $this->getStartHit();
    $config[] = 'hit:' . $this->getHits();
    ($r = $this->getRerankSize()) && ($config[] = 'rerank_size:' . $r);
    
    return implode(",", $config);
  }