Ldap Adapters

The Ldap Library uses adapters to interact with the actual LDAP implementation (client library). An adapter is a class that converts the interface of that particular implementation to AdapterInterface. This pattern allows for different LDAP implementations to be used by The Ldap Library in a pluggable manner. The Ldap Library itself provides an adapter named ExtLdap which makes use of the standard PHP ldap extension.

Each Ldap instance wraps an instance of AdapterInterface (the adapter) and interacts with particular LDAP implementation through this adapter. The adapter is feed to Ldap’s constructor when it’s being created. The whole process of adapter instantiation is done behind the scenes.

Adapter Factory

An adapter class is accompanied with its adapter factory. This configurable object creates adapter instances. Adapter factories implement AdapterFactoryInterface which defines two methods: configure() and createAdapter(). New adapter instances are created with createAdapter() according to configuration options provided earlier to configure().

Adapter factory may be specified when creating an Ldap instance. For this purpose, a preconfigured instance of the AdapterFactoryInterface shall be provided to Ldap’s static method createWithAdapterFactory():

1
2
3
4
5
6
use Korowai\Lib\Ldap\Ldap;
use Korowai\Lib\Ldap\Adapter\ExtLdap\AdapterFactory;

$config = ['uri' => 'ldap://ldap-service'];
$factory = new AdapterFactory($config);
$ldap = Ldap::createWithAdapterFactory($factory);

Alternatively, factory class name may be passed to createWithConfig() method:

1
2
3
4
5
use Korowai\Lib\Ldap\Ldap;
use Korowai\Lib\Ldap\Adapter\ExtLdap\AdapterFactory;

$config = ['uri' => 'ldap://ldap-service'];
$ldap = Ldap::createWithConfig($config, AdapterFactory::class);

In this case, a temporary instance of adapter factory is created internally, configured with $config and then used to create the actual adapter instance for Ldap.