Adldap\Query\Grammar::compileQuery PHP Method

compileQuery() public method

Compiles the Builder instance into an LDAP query string.
public compileQuery ( Builder $builder ) : string
$builder Builder
return string
    public function compileQuery(Builder $builder)
    {
        // Retrieve the query 'where' bindings.
        $wheres = $builder->getWheres();
        // Retrieve the query 'orWhere' bindings.
        $orWheres = $builder->getOrWheres();
        // Retrieve the query filter bindings.
        $filters = $builder->getFilters();
        // We'll combine all raw filters together first.
        $query = implode(null, $filters);
        // Compile wheres.
        $query = $this->compileWheres($wheres, $query);
        // Compile or wheres.
        $query = $this->compileOrWheres($orWheres, $query);
        // Count the total amount of filters.
        $total = count($wheres) + count($filters);
        // Make sure we wrap the query in an 'and' if using
        // multiple filters. We also need to check if only
        // one where is used with multiple orWheres, that
        // we wrap it in an `and` query.
        if ($total > 1 || count($wheres) === 1 && count($orWheres) > 0) {
            $query = $this->compileAnd($query);
        }
        return $query;
    }

Usage Example

Example #1
0
 /**
  * Compiles and returns the current query string.
  *
  * @return string
  */
 public function getQuery()
 {
     return $this->grammar->compileQuery($this);
 }