Core\Ldap\Dn::isWithin
$dn->isWithin(Core\Ldap\Dn $other): bool$dn->isWithin( Core\Ldap\Dn $other, ): bool
Checks if a DN is another DN, or an entry below it. The result is true or false.
Use it to check that an entry is in the part of the directory you expect, such as OU=Staff,DC=example,DC=test, before you change it.
Good to know: names and values are compared without case, so dc=EXAMPLE and DC=example are the same part. A DN is within itself.
Parameters
$otherCore\Ldap\DnThe DN to compare with, such asDn::parse('DC=example,DC=test').
Return value
Returns bool. true when this DN ends with every part of other.
Examples
In the staff unit
<?nvs// Shows how to check that an entry is in the staff unit before you change it.
var $staff = Core\Ldap\Dn::parse('OU=Staff,DC=example,DC=test');var $ann = Core\Ldap\Dn::parse('CN=Ann,OU=Staff,DC=example,DC=test');var $printer = Core\Ldap\Dn::parse('CN=Printer,OU=Devices,DC=example,DC=test');// This prints yes.echo $ann->isWithin($staff) ? 'yes' : 'no', "\n";// This prints no.echo $printer->isWithin($staff) ? 'yes' : 'no', "\n";yesnoCase does not matter
<?nvs// Shows that names and values are compared without case.
var $domain = Core\Ldap\Dn::parse('DC=example,DC=test');var $ann = Core\Ldap\Dn::parse('cn=Ann,ou=staff,dc=EXAMPLE,dc=Test');// This prints yes.echo $ann->isWithin($domain) ? 'yes' : 'no', "\n";yesItself and above
<?nvs// Shows that a DN is within itself, and is not within an entry below it.
var $staff = Core\Ldap\Dn::parse('OU=Staff,DC=example,DC=test');var $ann = $staff->child('CN', 'Ann');// This prints yes.echo $staff->isWithin($staff) ? 'yes' : 'no', "\n";// This prints no.echo $staff->isWithin($ann) ? 'yes' : 'no', "\n";yesno