Core\Ldap\Connection::Scope
Says how far below its base a search looks.
Core\Ldap\Connection::Scope is declared in the class Core\Ldap\Connection. The scope option of its method search takes it.
A directory is a tree of entries, and a search starts at one entry, its base. The scope option of a search is one of three cases. Scope::Base returns only the base entry itself, which is a quick way to read one entry with a filter. Scope::OneLevel returns the entries directly below base. Scope::Subtree returns base and every entry below it, at any depth.
A search without scope uses Scope::Subtree.
Examples
The examples below run with this configuration file.
# These examples use the LDAP directory server on this computer at port 16636.# `tls_ca_file` is the certificate that the server's certificate is checked against.[ldap.corp]url = "ldaps://127.0.0.1:16636"base = "DC=example,DC=test"user = "CN=Reader,OU=Company,DC=example,DC=test"password = "Novis-reader-1"tls_ca_file = "../../../../tests/db/ca.crt"timeout = "5s"
# The program may open the `corp` directory.[capabilities.ldap]connect = ["corp"]How far a search looks
<?nvs// Shows how `scope` changes which entries a search returns.// requires: samba-ad
var $corp = Core\Ldap::connect('corp');string $company = 'OU=Company,DC=example,DC=test';
// `Scope::Base` returns only the `base` entry itself. This prints `OU=Company,DC=example,DC=test`.foreach ($corp->search(Core\Ldap\Filter::present('objectClass'), { base: $company, scope: Core\Ldap\Connection::Scope::Base }) as Core\Ldap\Entry $unit) { echo $unit->dn(), "\n";}
// `Scope::OneLevel` returns the entries directly below `base`.// This prints Anna Berg and Carla Diaz, the two people in the sales department.var $sales = Core\Ldap\Filter::equals('department', 'Sales');foreach ($corp->search($sales, { base: $company, scope: Core\Ldap\Connection::Scope::OneLevel, sort: 'cn' }) as Core\Ldap\Entry $person) { echo $person->string('cn') ?? '', "\n";}OU=Company,DC=example,DC=testAnna BergCarla Diaz