LdapTools\Object\LdapObject::set PHP Method

set() public method

If a value already exists it will be replaced. If the value is empty the attribute will be cleared/reset.
public set ( string $attribute, mixed $value )
$attribute string
$value mixed
    public function set($attribute, $value)
    {
        if ($value === [] || $value === '' || $value === null) {
            return $this->reset($attribute);
        }
        if ($this->has($attribute)) {
            $attribute = $this->resolveAttributeName($attribute);
            $this->attributes[$attribute] = $value;
        } else {
            $this->attributes[$attribute] = $value;
        }
        $this->batches->add(new Batch(Batch::TYPE['REPLACE'], $attribute, $value));
        return $this;
    }

Usage Example

 function it_should_hydrate_a_ldap_object_wihtout_a_schema_with_batch_modification()
 {
     $ldapObject = new LdapObject(['dn' => 'cn=foo,dc=foo,dc=bar'], [], 'user', '');
     $ldapObject->set('givenName', 'Chad');
     $ldapObject->add('sn', 'Sikorra');
     $ldapObject->remove('sAMAccountName', 'csikorra');
     $ldapObject->reset('mail');
     $this->hydrateToLdap($ldapObject)->shouldBeEqualTo($this->batch);
     $this->hydrateToLdap($ldapObject)->shouldHaveCount(4);
 }
All Usage Examples Of LdapTools\Object\LdapObject::set