66use Illuminate \Support \Collection ;
77use Illuminate \Support \Facades \Log ;
88
9+ use App \Classes \LDAP \Attribute ;
10+ use App \Ldap \Entry ;
11+
912/**
1013 * Represents an LDAP AttributeType
1114 *
@@ -341,6 +344,11 @@ public function addUsedInObjectClass(string $name,bool $structural): void
341344 $ this ->used_in_object_classes ->put ($ name ,$ structural );
342345 }
343346
347+ private function factory (): Attribute
348+ {
349+ return Attribute \Factory::create (dn:'' ,attribute:$ this ->name ,values:[]);
350+ }
351+
344352 /**
345353 * Gets the names of attributes that are an alias for this attribute (if any).
346354 *
@@ -548,6 +556,7 @@ public function validation(array $array): ?array
548556 {
549557 // For each item in array, we need to get the OC hierarchy
550558 $ heirachy = collect ($ array )
559+ ->flatten ()
551560 ->filter ()
552561 ->map (fn ($ item )=>config ('server ' )
553562 ->schema ('objectclasses ' ,$ item )
@@ -556,14 +565,17 @@ public function validation(array $array): ?array
556565 ->flatten ()
557566 ->unique ();
558567
568+ // Get any config validation
559569 $ validation = collect (Arr::get (config ('ldap.validation ' ),$ this ->name_lc ,[]));
560570
571+ $ nolangtag = sprintf ('%s.%s.0 ' ,$ this ->name_lc ,Entry::TAG_NOTAG );
572+
561573 // Add in schema required by conditions
562574 if (($ heirachy ->intersect ($ this ->required_by_object_classes ->keys ())->count () > 0 )
563575 && (! collect ($ validation ->get ($ this ->name_lc ))->contains ('required ' ))) {
564576 $ validation
565- ->prepend (array_merge (['required ' ,'min:1 ' ],$ validation ->get ($ this -> name_lc . ' .0 ' ,[])),$ this -> name_lc . ' .0 ' )
566- ->prepend (array_merge (['required ' ,'array ' ,'min:1 ' ],$ validation ->get ($ this ->name_lc ,[])),$ this ->name_lc );
577+ ->prepend (array_merge (['required ' ,'min:1 ' ],$ validation ->get ($ nolangtag ,[])),$ nolangtag )
578+ ->prepend (array_merge (['required ' ,'array ' ,'min:1 ' ,( $ this -> factory ()-> no_attr_tags ? ' max:1 ' : NULL ) ],$ validation ->get ($ this ->name_lc ,[])),$ this ->name_lc );
567579 }
568580
569581 return $ validation ->toArray ();
0 commit comments