LdapTools\Object\LdapObject::has PHP Method

has() public method

Check to see if a specific attribute exists. Optionally check if it exists with a specific value.
public has ( string $attribute, mixed $value = null ) : boolean
$attribute string
$value mixed
return boolean
    public function has($attribute, $value = null)
    {
        if (!array_key_exists(MBString::strtolower($attribute), MBString::array_change_key_case($this->attributes))) {
            return false;
        }
        return is_null($value) ?: $this->attributeHasValue($attribute, $value);
    }

Usage Example

 /**
  * The DN attribute must be present to perform LDAP operations.
  *
  * @param LdapObject $ldapObject
  */
 protected function validateObject(LdapObject $ldapObject)
 {
     if (!$ldapObject->has('dn')) {
         throw new InvalidArgumentException('To persist/delete/move/restore a LDAP object it must have the DN attribute.');
     }
 }