Skip to content
PHP Ecosystem
Explore

Directory

API reference › LDAP › Directory

classyii2\extensions\ldap\Directory
Extendsyii\base\BaseObject
Implementsyii\base\BootstrapInterface, yii\base\Configurable
Sourcesrc/Directory.php

Registers named service-account connections for native LdapRecord models and explicit membership changes.

PropertyTypeDescriptionDefined by
$connectionsarray<array-key, mixed>Trusted application configuration keyed by connection name. Default: [].Directory
MethodDescriptionDefined by
__construct()Constructor.yii\base\BaseObject
__call()Calls the named method which is not a class method.yii\base\BaseObject
__get()Returns the value of an object property.yii\base\BaseObject
__isset()Checks if a property is set, i.e. defined and not null.yii\base\BaseObject
__set()Sets value of an object property.yii\base\BaseObject
__unset()Sets an object property to null.yii\base\BaseObject
bootstrap()Registers this application’s connections without replacing any existing connection or changing the default.Directory
canGetProperty()Returns a value indicating whether a property can be read.yii\base\BaseObject
canSetProperty()Returns a value indicating whether a property can be set.yii\base\BaseObject
className() staticReturns the fully qualified name of this class.yii\base\BaseObject
disconnect()Closes this component’s open LDAP handles without changing the registry.Directory
hasMethod()Returns a value indicating whether a method is defined.yii\base\BaseObject
hasProperty()Returns a value indicating whether a property is defined.yii\base\BaseObject
init()Initializes the object.yii\base\BaseObject
isReadConnection()Confirms that a query uses one of this component’s read connections.Directory
setMembership()Adds or removes one direct membership through an explicitly writable connection.Directory
unregister()Releases owned names and closes their handles before the application is recreated.Directory
createConnection() protectedCreates an unconnected LdapRecord connection using this package’s service-account transport.Directory
public function bootstrap(yii\base\Application $app): void

Registers this application’s connections without replacing any existing connection or changing the default.

Parameters

ParameterTypeDescription
$appyii\base\ApplicationApplication bootstrapping this component.

Throws

public function disconnect(): void

Closes this component’s open LDAP handles without changing the registry.

Subsequent operations reconnect as the original configured service account. Every handle is closed even if one of them fails; the first failure is then rethrown.

Throws

  • Throwable: if a connection cannot be closed.
public function isReadConnection(string $name, LdapRecord\Connection $connection): bool

Confirms that a query uses one of this component’s read connections.

Parameters

ParameterTypeDescription
$namestringName used to register the connection.
$connectionLdapRecord\ConnectionConnection instance used by the query.

Returns

bool: Whether the registry still owns the exact connection and it is not enabled for writes.

public function setMembership(LdapRecord\Models\ActiveDirectory\Group|LdapRecord\Models\OpenLDAP\Group $group, LdapRecord\Models\ActiveDirectory\User|LdapRecord\Models\OpenLDAP\User $user, bool $member): bool

Adds or removes one direct membership through an explicitly writable connection.

Both persisted models must be loaded on that connection and use the same supported schema. This does not change AD primary groups, follow nested groups, replace an entire member list, or delete any directory entry.

Parameters

ParameterTypeDescription
$groupLdapRecord\Models\ActiveDirectory\Group|LdapRecord\Models\OpenLDAP\GroupPersisted group to modify.
$userLdapRecord\Models\ActiveDirectory\User|LdapRecord\Models\OpenLDAP\UserPersisted user whose direct membership is changed.
$memberboolWhether to add the membership instead of removing it.

Returns

bool: Whether the LDAP modification succeeded.

Throws

public function unregister(): void

Releases owned names and closes their handles before the application is recreated.

Does not remove another component’s replacement connection. Call only after the application has stopped using native LDAP models and queries.

protected function createConnection(yii2\extensions\ldap\Endpoint $endpoint): LdapRecord\Connection

Creates an unconnected LdapRecord connection using this package’s service-account transport.

Parameters

ParameterTypeDescription
$endpointyii2\extensions\ldap\EndpointValidated settings for one connection.

Returns

LdapRecord\Connection: Service connection with no open LDAP handle.