PHPackages                             chanmix51/slapom - 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. [Database &amp; ORM](/categories/database)
4. /
5. chanmix51/slapom

ActiveLibrary[Database &amp; ORM](/categories/database)

chanmix51/slapom
================

Small Object Model Manager for LDAP

125.9k8[3 issues](https://github.com/chanmix51/SlapOM/issues)[6 PRs](https://github.com/chanmix51/SlapOM/pulls)PHP

Since Jul 6Pushed 9y ago1 watchersCompare

[ Source](https://github.com/chanmix51/SlapOM)[ Packagist](https://packagist.org/packages/chanmix51/slapom)[ RSS](/packages/chanmix51-slapom/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

SlapOM Small Object Model Manager for LDAP
==========================================

[](#slapom-small-object-model-manager-for-ldap)

**SlapOM** is a simple object model manager for LDAP. It allows you to **generate** and **hydrate** objects from a database using the LDAP protocol. It has been tested with Microsoft Active Directory (tm).

SlapOM works with PHP 5.3 and needs the php5-ldap extension module. It uses LDAP v3.

Project structure
-----------------

[](#project-structure)

```
├── documentation
│
├── lib
│   ├── SlapOM
│   └── Exception
│
└── tests
    ├── bootstrap
    ├── config
    ├── fixtures
    └── SlapOM
        ├── Tests
        └── Units
```

Generation and hydration example
--------------------------------

[](#generation-and-hydration-example)

Here is the scenario: you want to retrieve your "person" objectClass from the LDAP server and make its fields available in a User PHP class to display the user name, email and group informations.

### Step 1 - Create the inherited objects

[](#step-1---create-the-inherited-objects)

The first step is to create the object (aka entity or User) that will represent the "person" objectClass AND his mapper.

#### Entity class (must extend \\SlapOM\\Entity)

[](#entity-class-must-extend-slapomentity)

```
public class User extends \SlapOM\Entity
{
}
```

#### Mapper class (must extend \\SlapOM\\EntityMap and must be named "{Entity class name}Map")

[](#mapper-class-must-extend-slapomentitymap-and-must-be-named-entity-class-namemap)

The abstract class EntityMap contains an abstract method configure(); you must override this method to set up the required parameters.

```
public class UserMap extends \SlapOM\EntityMap
{

    protected function configure()
    {
        /* Set up the required options */
        $this->base_dn = 'dc=company,dc=com'
        $this->ldap_object_class = 'person';
        $this->entity_class = 'User';

        /* Set up the fields that you want to retrieve in your User class */
        // Standard String fields
        $this->addAttribute('firstname');
        $this->addAttribute('lastname');
        $this->addAttribute('mail');

        // Array field
        $this->addAttribute('objectclass', self::FIELD_MULTIVALUED);

        // Binary field
        $this->addAttribute('image', self::FIELD_BINARY);
    }
}
```

### Step 2 - Use it !

[](#step-2---use-it-)

Initialize the connection:

```
$connection = new SlapOM\Connection('localhost', 'cn=root', 'root');
```

Instantiate the mapper class:

```
$userMap = $connection->getMapFor('User');
```

Query all User entities in a $result array:

```
$result = $userMap->find();
```

Display results:

```

```

```
* Amar, Aaccf (user.0@maildomain.net) is objectClass:
  - person
  - organizationalperson
  - inetorgperson
  - top
* Atp, Aaren (user.1@maildomain.net) is objectClass:
  - person
  - organizationalperson
  - inetorgperson
  - top
* Atpco, Aarika (user.2@maildomain.net) is objectClass:
  - person
  - organizationalperson
  - inetorgperson
  - top
```

### Querying the database

[](#querying-the-database)

Of course, most of the time, you are not interested in fetching all entities from the database but only a subset of them. This can be done by setting the first parameter of the `find()` method with a normalized LDAP filter string such as:

```
$result = $userMap->find('(|(mail=*@maildomain.net)(name=user*))');
```

Note that the return value of the `getObjectClassFilter()` method will be prepended to your search string. The final search string will really be `(&(objectClass=user)(|(mail=*@maildomain.net)(name=user*)))`.

To manage more complex queries, you might use the `BinaryFilter` class:

```
$filter = \SlapOM\BinaryFilter::create("mail=*@maildomain.net")
    ->addOr("name=user*");

$result = $userMap->find((string) $filter);
```

In case you have the DN of a record, use the `fetch()` method to get the corresponding object:

```
$user = $userMap->fetch($dn);
```

### Projection operator

[](#projection-operator)

By default queries return collections that pop hydrated objects. These instances are by default fed with the fields declared in their corresponding map class. This behavior can be overloaded using the `getSearchFields()` method. Even though it is a good idea to declare the user password as a binary field in the user map class, it would not a good idea to fetch it from the database every time a user is retrieved. This method is the right place to strip (or add) fields from your searches.

### Dealing with entities

[](#dealing-with-entities)

SlapOM is an OMM hence entities do not know anything about the LDAP database nor their structure: they are just flexible data containers:

```
$user['mail'];         // $user->getMail();
$user->mail;           // $user->getMail();
$user->getMail();      // $user->get('mail');
$user->get('mail');    // $mail, raw data from LDAP
```

If you override the `getMail()` accessor, your calls to `$user['mail']` and `$user->mail` will reflect your overload. You cannot override the generic `get('mail')` as this is the only way to access to raw data extracted from the database.

Modifying the entity's data follows the same principle. To save an entity, just call the `save()` function of the mapper class and give it your modified object:

```
$user['mail'] = 'newMail@maildomain.net'; // $user->setMail('newMail@maildomain.net');
$user->isModified(); // true
$userMap->save($user);
$user->isModified(); // false
$user->isPersisted(); // true
```

Tests
-----

[](#tests)

The entire SlapOM library is unit tested with **Atoum** (). You can run the test suite with the command:

```
php /{wherever the atoum.phar is}/mageekguy.atoum.phar -d tests/SlapOM/Tests/Units/
```

Or class by class:

```
php tests/SlapOM/Tests/Units/{File name}
```

Before runnning the unit tests, you will need to load into your LDAP testing server the LDIF fixtures (test/fixtures/ldap\_datas.ldif) and edit the tests/config/config.ini file.

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.5% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/ad548f45d6e5ef262a3fccb208a92f2e31d6e53b71e989ec49fb3c7fe03dd020?d=identicon)[chanmix51](/maintainers/chanmix51)

---

Top Contributors

[![chanmix51](https://avatars.githubusercontent.com/u/81580?v=4)](https://github.com/chanmix51 "chanmix51 (62 commits)")[![cj-clx](https://avatars.githubusercontent.com/u/46033285?v=4)](https://github.com/cj-clx "cj-clx (3 commits)")[![hashar](https://avatars.githubusercontent.com/u/281689?v=4)](https://github.com/hashar "hashar (1 commits)")[![sanpii](https://avatars.githubusercontent.com/u/113045?v=4)](https://github.com/sanpii "sanpii (1 commits)")

### Embed Badge

![Health badge](/badges/chanmix51-slapom/health.svg)

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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