symfony/ldap
Symfony LDAP Component: a PHP LDAP client built on top of the PHP ldap extension. Stable since Symfony 3.1 (earlier versions were internal and may break). Includes docs and contribution resources via the main Symfony repository.
LdapClient, Entry, Query) maps well to Laravel’s service container and dependency injection patterns.AuthenticatesUsers trait with a standardized LdapClient::bind().users table via LdapClient::search() + Entry::fromDn().memberOf) to Laravel roles (e.g., Gate::define()).(uid=*)) and attribute mapping.ldap extension (may need pecl install ldap or server configuration).LdapClient as a singleton in config/app.php:
'ldap' => fn($app) => new \Symfony\Component\Ldap\LdapClient($app['config']['ldap']),
bind() method to inject the client into controllers/services.Model observers or queues to sync LDAP changes to Eloquent models (e.g., User::updated()).ldap extension must be enabled (shared hosting may block this).Entry mappings.LdapClient reuse or a custom pool).memberOf overlay)?givenName, mail) map to Laravel models?php-ldap extension (enable via pecl or server config).options-resolver (included as a dependency).spomky-labs/ldap (Symfony-based, but less maintained).ldap_connect() calls).osixia/openldap).LdapService class:
class LdapService {
public function __construct(private LdapClient $client) {}
public function findUser(string $dn): ?User {
$entry = $this->client->findEntry($dn);
return User::fromLdapEntry($entry);
}
}
deprecated() helper.LdapClient to the container and inject into:
AuthenticatesUsers with LDAP binds.Auth::guard('ldap')).Model events (retrieved, saved) to sync LDAP ↔ DB.User::observe(function ($model) {
if ($model->wasRecentlyCreated) {
$model->syncToLdap();
}
});
LdapClient in unit tests (use Symfony’s MockLdapClient).Auth::attempt() → LdapClient::bind()).options-resolver adds ~50KB (negligible).php.ini:
ldap.trace_level = 255
LdapException for error handling.default_socket_timeout in LdapClient.Query::limit().LdapClient is lightweight; scale Laravel horizontally.LdapClient instances across requests (avoid per-request overhead).Redis::remember()).LdapException catch).LdapClient to use LDAP server replicas.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| LDAP Server Down | Auth failures, user sync halts | Fallback to local cache or gracefully degrade. |
| Network Partition | Timeouts on LDAP operations | Increase default_socket_timeout. |
| Schema Changes (e.g., AD) | Broken attribute mappings | Version LDAP queries (e.g., objectClass=*). |
| Credential Leaks | Security risk | Use LdapClient::unbind() and avoid logging DNs. |
| Large Search Results | Memory exhaustion | Paginate with `Query::limit |
How can I help you explore Laravel packages today?