Core\Ldap\Dn::of
Core\Ldap\Dn::of(string $attribute, string $value): Core\Ldap\DnCore\Ldap\Dn::of( string $attribute, string $value, ): Core\Ldap\Dn
Returns a DN with one part, attribute=value, such as DC=test.
The value can come from user input. Each special character in it, such as ,, + or =, is escaped. So the value stays one value, and it cannot add a part to the DN. Use child to add more parts below this one.
Good to know: the attribute name cannot be tainted. An empty value throws a LogicError, and so does an attribute that is not a name.
Parameters
$attributestringThe attribute's name, such asCNorOU. It cannot betainted.$valuestringThe value, such asAnn Lee. It can betainted. A,,+,=or other special character in it is escaped, so it stays one value.
Return value
Returns Core\Ldap\Dn. A Core\Ldap\Dn.
Errors
LogicErrorThe attribute is not an attribute name, or the value is empty.
Examples
One part
<?nvs// Shows how to make a DN with one part.
var $top = Core\Ldap\Dn::of('DC', 'test');// This prints DC=test.echo $top->toString(), "\n";DC=testA value from a form
<?nvs// Shows how a value from user input is escaped.
// This text came from a form, so it is `tainted`.tainted string $name = 'Lee, Ann';var $dn = Core\Ldap\Dn::of('CN', $name);// The comma is escaped. This prints CN=Lee\, Ann.echo $dn->toString(), "\n";CN=Lee\, AnnAn empty value
<?nvs// Shows the error for an empty value.
try { var $dn = Core\Ldap\Dn::of('CN', ''); echo $dn->toString(), "\n";} catch (LogicError $error) { // This prints Core\Ldap\Dn::of: the value is empty. echo $error->message, "\n";}Core\Ldap\Dn::of: the value is empty