LdapRecord

A fully-featured, ActiveRecord-style LDAP ORM for PHP supporting Active Directory, OpenLDAP, and FreeIPA.

Library
Composer
vv4.0.6
580stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
63/100Good
Development Activity48
Maintenance52
Community64
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
79/100Good
Architecture85
Code Quality82
Innovation82
Learning Curve68

LdapRecord is a fully-featured LDAP ORM for PHP that brings an ActiveRecord-style modeling experience to directory servers. Instead of assembling raw LDAP filters and parsing entries by hand, you work with expressive model classes and a fluent query builder, with prebuilt models for Active Directory, OpenLDAP-style DirectoryServer, and FreeIPA schemas.

Beyond querying, LdapRecord handles connection management across multiple directories, LDAP authentication, attribute casting and mutation, events, and a dedicated testing harness that lets you fake directory interactions in tests. Its API is heavily inspired by Laravel’s Eloquent, making it immediately familiar to PHP developers who have used an Eloquent-style ORM.

What You Get

  • ActiveRecord-style models with attribute casting, mutators, and relationships
  • A fluent, Eloquent-inspired query builder for LDAP search filters
  • Prebuilt model sets for Active Directory, OpenLDAP DirectoryServer, and FreeIPA
  • Multi-directory connection management via a Container/ConnectionManager
  • LDAP authentication plus a Testing harness for faking directory interactions

Common Use Cases

  • Authenticating application users against Active Directory or OpenLDAP
  • Reading and updating directory objects (users, groups, OUs) from PHP
  • Synchronizing directory data into an application’s own database

Under The Hood

Architecture — LdapRecord layers an ActiveRecord ORM over PHP’s ext-ldap. Connection and Ldap/LdapInterface wrap the raw protocol; a Container and ConnectionManager register and resolve named connections. The Models/ tree centers on a base Entry model with concerns for attributes, casting, and events, and provides schema-specific subtrees (Models/ActiveDirectory, Models/DirectoryServer, Models/FreeIPA). The Query/ builder compiles fluent method chains into LDAP search filters, an Auth/ layer handles bind-based authentication, and a Testing/ namespace provides a fake LDAP implementation for tests.

Tech Stack — PHP >=8.1 requiring ext-ldap, ext-json, and ext-iconv. It reuses Laravel components (illuminate/contracts, illuminate/collections), nesbot/carbon for dates, and PSR interfaces (psr/log, psr/simple-cache) — the Eloquent-like feel comes directly from building on Illuminate collections and contracts.

Code Quality — The tests/ directory is split into Unit and Integration suites with a shared TestCase, and the shipped Testing harness signals a strong testability focus. Error handling is granular, with a hierarchy of typed exceptions (LdapRecordException, ConnectionException, ContainerException) and a DetectsErrors/DetailedError mechanism for interpreting LDAP result codes.

API Design — The public API deliberately mirrors Eloquent — Model::query(), where(), find(), save() — so PHP developers are productive immediately. Directory-specific models encode schema knowledge (object classes, attribute names) so callers work with meaningful properties rather than raw DNs and attribute arrays.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search