diff --git a/src/Schema.php b/src/Schema.php index c156e46..8815530 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -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 $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; + } + } diff --git a/src/Schema/ObjectClass.php b/src/Schema/ObjectClass.php index 12fa3ac..7cb7028 100644 --- a/src/Schema/ObjectClass.php +++ b/src/Schema/ObjectClass.php @@ -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; + } }