Schema: add has_attribute() method

This commit is contained in:
Benjamin Renard 2023-03-21 16:54:12 +01:00
parent 39dd48e0df
commit 21eb101321
2 changed files with 35 additions and 0 deletions

View file

@ -217,4 +217,26 @@ class Schema {
return $this -> _get_entry('Syntax', $name_or_oid);
}
/**
* Check if given objectclass have the specified attribute
* @param string $attr The attribute name
* @param string|array<string> $objectclasses List of objectclass
* @return bool
*/
public function has_attribute($attr, ...$objectclasses) {
foreach($objectclasses as $objectclass) {
if (is_array($objectclass)) {
if (call_user_func_array(array($this, 'has_attribute'), array_merge(array($attr), $objectclass)))
return true;
continue;
}
$oc = $this -> objectclass($objectclass);
if (!$oc)
continue;
if ($oc->has_attribute($attr))
return true;
}
return false;
}
}

View file

@ -74,4 +74,17 @@ class ObjectClass extends SchemaEntry {
}
return parent::__get($key);
}
/**
* Check if the given attribute is used by the objectclass
* @param string $attr The attribute name
* @return bool
*/
public function has_attribute($attr) {
if (in_array($attr, $this->must))
return true;
if (in_array($attr, $this->may))
return true;
return false;
}
}