Skip to content
PHP Ecosystem
Explore

UserSynchronizer

API reference › LDAP › UserSynchronizer

final classyii2\extensions\ldap\UserSynchronizer
Sourcesrc/UserSynchronizer.php

Reads explicitly mapped LDAP user attributes in batches and passes them to application-owned persistence.

MethodDescriptionDefined by
__construct()Creates a synchronizer restricted to the directory component’s registered read connections.UserSynchronizer
sync()Upserts each row using the configured connection name and the directory’s stable user identifier.UserSynchronizer
public function __construct(yii2\extensions\ldap\Directory $directory)

Creates a synchronizer restricted to the directory component’s registered read connections.

Parameters

ParameterTypeDescription
$directoryDirectory
public function sync(LdapRecord\Query\Model\Builder $query, array<non-empty-string, non-empty-string> $attributes, Closure(string, string, array<string, mixed>): void $upsert, int $pageSize = 500): int

Upserts each row using the configured connection name and the directory’s stable user identifier.

Missing or unreadable attributes are passed as null and all available values retain their native model representation. No local users are deleted. If a read or upsert fails, earlier successful upserts are not rolled back.

Parameters

ParameterTypeDescription
$queryLdapRecord\Query\Model\BuilderUser query built on an explicitly named read connection.
$attributesarray<non-empty-string, non-empty-string>Map of application field to LDAP attribute.
$upsertClosure(string, string, array<string, mixed>): voidPersists one user using the connection and GUID as the key.
$pageSizeintLDAP page size; the server must support paged results.

Returns

int: Number of users passed successfully to the persistence callback.

Throws

  • yii\base\InvalidConfigException: if the mapping, query, or page size is invalid.
  • DirectoryUnavailableException: if a result lacks a stable identifier or paging does not complete.
  • LdapRecord\LdapRecordException: if LdapRecord cannot bind or query the directory. Upsert exceptions propagate unchanged.