Core\Ldap\Change::add
Core\Ldap\Change::add(string $attribute, mixed $value): Core\Ldap\ChangeCore\Ldap\Change::add( string $attribute, mixed $value, ): Core\Ldap\Change
Returns a Core\Ldap\Change that adds values to one attribute of a directory entry. You give the attribute's name and one value or a list of values.
The change does nothing on its own. You put it in a list and pass the list to a connection's modify method. modify sends every change in the list in one request, so the server makes all of them or none of them.
Good to know: the entry must not have the value yet. If it has, modify throws an LdapError and the server changes nothing. The attribute name must start with a letter and contain only letters, digits and -. Any other name throws a LogicError at once. A value is written in the form that Core\Ldap\Entry returns it, such as an int, a Core\Uuid or an Instant.
Parameters
$attributestringThe attribute's name, such asdescription. It cannot betainted.$valuemixedOne value, or a list of values. A value is written in the form the methods ofEntryreturn it, such as anint, aUuidor anInstant.
Return value
Returns Core\Ldap\Change. The change.
Errors
LogicErrorattributeis not an attribute name.
Examples
Add a phone number
<?nvs// Shows how to prepare a change that adds a phone number to a user.
var $phone = Core\Ldap\Change::add('telephoneNumber', '+43 1 234 5678');// A connection's `modify` method sends this list to the server. This prints 1.array<Core\Ldap\Change> $changes = [$phone];echo Core\Arr::count($changes), "\n";1Add several values
<?nvs// Shows how to add several values to one attribute with one change.
array<string> $numbers = ['+43 1 111 2222', '+43 1 333 4444'];// One change adds both numbers. This prints 1 change, 2 numbers.array<Core\Ldap\Change> $changes = [Core\Ldap\Change::add('otherTelephone', $numbers)];echo Core\Arr::count($changes), ' change, ', Core\Arr::count($numbers), " numbers\n";1 change, 2 numbersA name with a space
<?nvs// Shows the error for a name that is not an attribute name.
try { var $change = Core\Ldap\Change::add('phone number', '+43 1 234 5678'); echo "the change is ready\n";} catch (LogicError $refusal) { // A name has no spaces, so this prints the error message. echo $refusal->message, "\n";}Core\Ldap\Change::add: `phone number` is not an attribute name. A name starts with a letter and has only letters, digits and `-`, such as `sAMAccountName`