PHPackages                             avadaneidanut/ldapquery - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. avadaneidanut/ldapquery

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

avadaneidanut/ldapquery
=======================

A light weight package for easily building LDAP advanced filter queries.

v1.0.0(10y ago)4717.8k↓27.8%4MITPHPPHP &gt;=5.6

Since May 18Pushed 10y ago2 watchersCompare

[ Source](https://github.com/avadaneidanut/ldapquery)[ Packagist](https://packagist.org/packages/avadaneidanut/ldapquery)[ RSS](/packages/avadaneidanut-ldapquery/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

LDAP Query Builder
==================

[](#ldap-query-builder)

[![Latest Stable Version](https://camo.githubusercontent.com/d69b17a15b347d616f69ee16cb4168f55334a16b02c79bc1bdf1d5252709a973/68747470733a2f2f706f7365722e707567782e6f72672f61766164616e656964616e75742f6c64617071756572792f762f737461626c65)](https://packagist.org/packages/avadaneidanut/ldapquery) [![Total Downloads](https://camo.githubusercontent.com/160e9b35edbd0e7c7d701f23b67ee591d87256848145e9d9d30943c73b6bf336/68747470733a2f2f706f7365722e707567782e6f72672f61766164616e656964616e75742f6c64617071756572792f646f776e6c6f616473)](https://packagist.org/packages/avadaneidanut/ldapquery) [![Latest Unstable Version](https://camo.githubusercontent.com/1feb8afcba9998ea17dc8d21b804b9db414c765b7a45670b90d82ffa9c7bdd1f/68747470733a2f2f706f7365722e707567782e6f72672f61766164616e656964616e75742f6c64617071756572792f762f756e737461626c65)](https://packagist.org/packages/avadaneidanut/ldapquery) [![License](https://camo.githubusercontent.com/d68df8a80756ac06a1ef4414428f747108fd70ef134da26d7892977120b854cf/68747470733a2f2f706f7365722e707567782e6f72672f61766164616e656964616e75742f6c64617071756572792f6c6963656e7365)](https://packagist.org/packages/avadaneidanut/ldapquery) [![Build Status](https://camo.githubusercontent.com/f33fa18f75c5413f258b53990227203773c8361730242856b848d3859b357e6d/68747470733a2f2f7472617669732d63692e6f72672f61766164616e656964616e75742f6c64617071756572792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/avadaneidanut/ldapquery)

LDAP Query Builder is simple tool for easily generate queries for LDAP filtering. Quick example:

```
$query = \LdapQuery\Builder::create()->where('attrBar', 'value')
    ->where('attrFoo', '' 'value2')
    ->orWhere('attrBaz', [1, 2, 3, 4, 5, 6, 7, 8, 9])
    ->where(function($builder) {
        $builder->where('bla', 'bla2')
            ->orWhere('bla3', 'bla1');
    })
    ->stringify()
;
```

Output:

```
(&(|(&(attrBar=value)(!(attrFoo=value2)))(|(attrBaz=1)(attrBaz=2)(attrBaz=3)(attrBaz=4)(attrBaz=5)(attrBaz=6)(attrBaz=7)(attrBaz=8)(attrBaz=9)))(|(bla=bla2)(bla3=bla1)))

```

If you want to examine queries generated and don't manually separate groups just:

```
$builder = new \LdapQuery\Builder;
$builder->where('attrBar', 'value')
    ->where('attrFoo', '' 'value2')
    ->orWhere('attrBaz', [1, 2, 3, 4, 5, 6, 7, 8, 9])
    ->where(function($builder) {
        $builder->where('bla', 'bla2')
            ->orWhere('bla3', 'bla1');
    });

$builder->toArray(); # will generate a nice output
```

Output:

```
(&
   (|
      (&
         (attrBar=value)
         (!
             (attrFoo=value2)
         )
      )
      (|
         (attrBaz=1)
         (attrBaz=2)
         (attrBaz=3)
         (attrBaz=4)
         (attrBaz=5)
         (attrBaz=6)
         (attrBaz=7)
         (attrBaz=8)
         (attrBaz=9)
      )
   )
   (|
      (bla=bla2)
      (bla3=bla1)
   )
)

```

Usage with sympfony ldap component:

```
use LdapQuery\Builder;
use Symfony\Component\Ldap\LdapClient;

$client = new LdapClient('ldap.example.com');
$client->bind('uid=AB1234,ou=people,o=world', 'secretpassword');

$builder = new Builder;

$details = $client->find(
    'ou=people,o=world',
    (string)$builder->where('uid', 'AB123*')->where('cn', '~=','*Danut*'),
    ['uid','cn','mail','office','mobile']
);
```

### Available methods on Builder class

[](#available-methods-on-builder-class)

```
/**
 * Add a where clause to the LDAP Query. Defaulted to & logical, acts like a andWhere.
 *
 * @param  string|Closure    $attribute
 * @param  string|array|null $operator
 * @param  string|array|null $value
 * @param  string|null       $wildcard
 * @param  bool              $escape
 * @param  string            $logical
 *
 * @return $this
 *
 * @throws GrammarException
 */
public function where($attribute, $operator = null, $value = null, $wildcard = null, $escape = true, $negation = false, $logical = '&');

/**
 * Add a or where clause to the LDAP Query.
 *
 * @param  string|Closure   $attribute
 * @param  string|array|null $operator
 * @param  string|array|null $value
 * @param  string|null       $wildcard
 * @param  bool              $escape
 *
 * @return $this
 *
 * @throws GrammarException
 */
public function orWhere($attribute, $operator = null, $value = null, $wildcard = null, $escape = true, $negation = false);

/**
 * Convert Group object to a string, LDAP valid query group.
 *
 * @return string
 */
public function stringify();

/**
 * Convert Builder object to array.
 *
 * @return array
 */
public function toArray();
```

### Dynamic where clauses

[](#dynamic-where-clauses)

LdapQuery\\Builder class has plenty dynamic "where clauses" that are transformed automatically calls to "where" or "orWhere" methods with arguments translatted from method name. This can be used as any other method example:

```
$builder->orWhereBegins('attribute', 'value'); will be translated in
$builder->orWhere('attribute', 'value', null, 'begins', true);
```

Available Dynamic where clauses

```
// whereRaw - where attribute unescaped value
$builder->whereRaw('foo', 'bar*');
print $builder; // (foo=bar*)

// orWhereRaw - or where attribute unescaped value
$builder->where('foo', 'bar')
    ->orWhereRaw('foo', 'baz*');
print $builder; // (|(foo=bar)(foo=baz*))
```

```
// whereNot - where attribute not value
$builder->whereNot('foo', 'bar');
print $builder; // (!(foo=bar))

// whereNotRaw - where attribute not unescaped value
$builder->whereNotRaw('foo', 'bar*');
print $builder; // (!(foo=bar*))

// orWhereNotRaw - or where attribute not unescaped value
$builder->where('foo', 'bar')
  ->orWhereNotRaw('foo', 'baz*');
print $builder;  // (|(foo=bar)(!(foo=baz*)))
```

```
// whereBegins - where attribute begins with value
$buidler->whereBegins('foo', 'b');
print $builder; // (foo=b*)

// whereBeginsRaw - where attribute begins with unescaped value
$builder->whereBeginsRaw('foo', 'b)');
print $builder; // (foo=b)*)

// whereBeginsNot - where attribute not begins with value
$builder->whereNotBegins('foo', 'b');
print $builder; // (!(foo=b*))

// whereBeginsNotRaw - where attribute not begins with unescaped value
$builder->whereNotBeginsRaw('foo', 'b()');
print $builder; // (!(foo=b()*))

// orWhereBegins - or where attribute begins with value
$builder->where('foo', 'bar')
    ->orWhereBegins('foo', 'b');
print $builder; // (|(foo=bar)(foo=b*))

// orWhereBeginsRaw - or where attribute begins with unescaped value
$builder->where('foo', 'bar')
    ->orWhereBeginsRaw('foo', 'b()');
print $builder; // (|(foo=bar)(foo=b()*))

// orWhereBeginsNot - or where attribute not begins with value
$builder->where('foo', 'bar')
    ->orWhereBeginsNot('foo', 'b');
print $builder; // (|(foo=bar)(!(foo=b*)))

// orWhereBeginsNotRaw - or where attribute not begins with unescaped value
$builder->where('foo', 'bar')
    ->orWhereBeginsNotRaw('foo', 'b()');
print $builder; // (|(foo=bar)(!(foo=b()*)))
```

```
// whereEnds - where attribute ends with value
$buidler->whereEnds('foo', 'b');
print $builder; // (foo=*b)

// whereEndsRaw - where attribute ends with unescaped value
$builder->whereEndsRaw('foo', 'b)');
print $builder; // (foo=*b))

// whereEndsNot - where attribute not ends with value
$builder->whereNotEnds('foo', 'b');
print $builder; // (!(foo=*b))

// whereEndsNotRaw - where attribute not ends with unescaped value
$builder->whereNotEndsRaw('foo', 'b()');
print $builder; // (!(foo=*b()))

// orWhereEnds - or where attribute ends with value
$builder->where('foo', 'bar')
    ->orWhereEnds('foo', 'b');
print $builder; // (|(foo=bar)(foo=*b))

// orWhereEndsRaw - or where attribute ends with unescaped value
$builder->where('foo', 'bar')
    ->orWhereEndsRaw('foo', 'b()');
print $builder; // (|(foo=bar)(foo=*b()))

// orWhereEndsNot - or where attribute not ends with value
$builder->where('foo', 'bar')
    ->orWhereEndsNot('foo', 'b');
print $builder; // (|(foo=bar)(!(foo=*b)))

// orWhereEndsNotRaw - or where attribute not ends with unescaped value
$builder->where('foo', 'bar')
    ->orWhereEndsNotRaw('foo', 'b()');
print $builder; // (|(foo=bar)(!(foo=*b())))
```

```
// whereLike - where attribute like value
$buidler->whereLike('foo', 'b');
print $builder; // (foo=*b*)

// whereLikeRaw - where attribute like unescaped value
$builder->whereLikeRaw('foo', 'b)');
print $builder; // (foo=*b)*)

// whereLikeNot - where attribute not like value
$builder->whereNotLike('foo', 'b');
print $builder; // (!(foo=*b*))

// whereLikeNotRaw - where attribute not like unescaped value
$builder->whereNotLikeRaw('foo', 'b()');
print $builder; // (!(foo=*b()*))

// orWhereLike - or where attribute like value
$builder->where('foo', 'bar')
    ->orWhereLike('foo', 'b');
print $builder; // (|(foo=bar)(foo=*b*))

// orWhereLikeRaw - or where attribute like unescaped value
$builder->where('foo', 'bar')
    ->orWhereLikeRaw('foo', 'b()');
print $builder; // (|(foo=bar)(foo=*b()*))

// orWhereLikeNot - or where attribute not like value
$builder->where('foo', 'bar')
    ->orWhereLikeNot('foo', 'b');
print $builder; // (|(foo=bar)(!(foo=*b*)))

// orWhereLikeNotRaw - or where attribute not like unescaped value
$builder->where('foo', 'bar')
    ->orWhereLikeNotRaw('foo', 'b()');
print $builder; // (|(foo=bar)(!(foo=*b()*)))
```

### Installation

[](#installation)

LdapQuery requires composer to install

```
$ composer require avadaneidanut/ldapquery
```

### Development

[](#development)

Want to contribute? Great! Can't wait to hear from you!

License
-------

[](#license)

MIT

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3652d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/60b6b630493892f8fadd098a150ddec366bf793d6d62effe15455b0f2e430e93?d=identicon)[avadaneidanut](/maintainers/avadaneidanut)

---

Top Contributors

[![danutavadanei](https://avatars.githubusercontent.com/u/13782979?v=4)](https://github.com/danutavadanei "danutavadanei (35 commits)")

---

Tags

ldapactive directorywindowsldapqueryldap querywindows serverldap filters

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/avadaneidanut-ldapquery/health.svg)

```
[![Health](https://phpackages.com/badges/avadaneidanut-ldapquery/health.svg)](https://phpackages.com/packages/avadaneidanut-ldapquery)
```

###  Alternatives

[symfony/ldap

Provides a LDAP client for PHP on top of PHP's ldap extension

1407.5M46](/packages/symfony-ldap)[directorytree/ldaprecord

A fully-featured LDAP ORM.

5782.9M10](/packages/directorytree-ldaprecord)[ldaptools/ldaptools

LdapTools is a feature-rich LDAP library for PHP 5.6+.

204263.9k1](/packages/ldaptools-ldaptools)[adldap/adldap

A PHP LDAP Library for Active Directory Manipulation

429170.1k9](/packages/adldap-adldap)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
