diff --git a/app/Classes/LDAP/Attribute/ObjectClass.php b/app/Classes/LDAP/Attribute/ObjectClass.php index aa6da48..8ae69ad 100644 --- a/app/Classes/LDAP/Attribute/ObjectClass.php +++ b/app/Classes/LDAP/Attribute/ObjectClass.php @@ -5,27 +5,31 @@ namespace App\Classes\LDAP\Attribute; use Illuminate\Contracts\View\View; use Illuminate\Support\Collection; -use App\Classes\LDAP\{Attribute,Server}; +use App\Classes\LDAP\Attribute; /** * Represents an ObjectClass Attribute */ final class ObjectClass extends Attribute { - // Which of the values is the structural object class - protected Collection $structural; + // The schema ObjectClasses for this objectclass of a DN + protected Collection $oc_schema; public function __construct(string $name,array $values) { parent::__construct($name,$values); - $this->structural = collect(); + $this->oc_schema = config('server') + ->schema('objectclasses') + ->filter(fn($item)=>$this->values->contains($item->name)); + } - // Determine which of the values is the structural objectclass - foreach ($values as $oc) { - if ((new Server)->schema('objectclasses',$oc)->isStructural()) - $this->structural->push($oc); - } + public function __get(string $key): mixed + { + return match ($key) { + 'structural' => $this->oc_schema->filter(fn($item) => $item->isStructural()), + default => parent::__get($key), + }; } /** @@ -36,7 +40,9 @@ final class ObjectClass extends Attribute */ public function isStructural(string $value): bool { - return $this->structural->contains($value); + return $this->structural + ->map(fn($item)=>$item->name) + ->contains($value); } public function render(bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE): View diff --git a/app/Classes/LDAP/Schema/AttributeType.php b/app/Classes/LDAP/Schema/AttributeType.php index 7b48b2f..b5482f5 100644 --- a/app/Classes/LDAP/Schema/AttributeType.php +++ b/app/Classes/LDAP/Schema/AttributeType.php @@ -334,10 +334,10 @@ final class AttributeType extends Base { * * @param string $name The name of the objectClass to add. */ - public function addUsedInObjectClass(string $name): void + public function addUsedInObjectClass(string $name,bool $structural): void { - if (! $this->used_in_object_classes->contains($name)) - $this->used_in_object_classes->push($name); + if (! $this->used_in_object_classes->has($name)) + $this->used_in_object_classes->put($name,$structural); } /** diff --git a/app/Classes/LDAP/Server.php b/app/Classes/LDAP/Server.php index 81b7553..f215c17 100644 --- a/app/Classes/LDAP/Server.php +++ b/app/Classes/LDAP/Server.php @@ -442,7 +442,7 @@ final class Server // Add Used In. foreach ($oclass_attrs as $attr_name) if ($this->attributetypes->has(strtolower($attr_name))) - $this->attributetypes[strtolower($attr_name)]->addUsedInObjectClass($object_class->name); + $this->attributetypes[strtolower($attr_name)]->addUsedInObjectClass($object_class->name,$object_class->isStructural()); // Add Required By. foreach ($must_attrs as $attr_name) diff --git a/resources/views/fragment/schema/attributetypes.blade.php b/resources/views/fragment/schema/attributetypes.blade.php index dfcfc12..ba25b20 100644 --- a/resources/views/fragment/schema/attributetypes.blade.php +++ b/resources/views/fragment/schema/attributetypes.blade.php @@ -90,16 +90,21 @@ @lang('Used by ObjectClasses') - + @if ($o->used_in_object_classes->count()) - @foreach ($o->used_in_object_classes as $class) - @if ($loop->index) @endif + @foreach ($o->used_in_object_classes as $class => $structural) + @if($structural) + + @endif {{ $class }} + @if($structural) + + @endif @endforeach @else @lang('(none)') @endif - + @lang('Force as MAY by config')@lang($o->forced_as_may ? 'Yes' : 'No')