6
6
7
7
/**
8
8
* Uses magic __get to return $this->entry->getAttribute($x) or $this->entry->getAttribute($x)[0]
9
- * $attributes_array is a case sensitive list of LDAP attribute names that should be an array
10
- * $attributes_non_array is a case sensitive list of LDAP attribute names that should be a single
9
+ * $attributes_array is a list of LDAP attribute names (lowercase only!) that should be an array
10
+ * $attributes_non_array is a list of LDAP attribute names (lowercase only!) that should be a single
11
11
* value instead of an array
12
12
* $entry is a PHPOpenLDAPer\LDAPEntry
13
13
* @since 8.3.0
@@ -17,10 +17,29 @@ class ObjectClass
17
17
private ?LDAPEntry $ entry = null ; // define in constructor of child class
18
18
protected static array $ attributes_array = [];
19
19
protected static array $ attributes_non_array = [];
20
+ private $ validated = false ;
21
+
22
+ private function ensureAttributeListsValidated ()
23
+ {
24
+ if ($ this ->validated ) {
25
+ return ;
26
+ }
27
+ assert (
28
+ array_reduce (
29
+ array_merge (static ::$ attributes_array , static ::$ attributes_non_array ),
30
+ fn ($ carry , $ x ) => $ carry && is_string ($ x ) && $ x === strtolower ($ x ),
31
+ true
32
+ ),
33
+ "attributes_array and attributes_non_array must be only lowercase strings "
34
+ );
35
+ $ this ->validated = true ;
36
+ }
20
37
21
38
public function __get (string $ property ): mixed
22
39
{
23
40
assert (!is_null ($ this ->entry ));
41
+ $ this ->ensureAttributeListsValidated ();
42
+ $ property = strtolower ($ property );
24
43
if (in_array ($ property , static ::$ attributes_array , true )) {
25
44
return $ this ->entry ->getAttribute ($ property );
26
45
}
@@ -36,7 +55,10 @@ public function __get(string $property): mixed
36
55
37
56
public function __isset (string $ property ): bool
38
57
{
58
+ $ this ->ensureAttributeListsValidated ();
59
+ $ property = strtolower ($ property );
39
60
assert (!is_null ($ this ->entry ));
61
+ $ this ->assert_attribute_lists_are_lowercase ();
40
62
if (in_array ($ property , static ::$ attributes_array , true )
41
63
|| in_array ($ property , static ::$ attributes_non_array , true )
42
64
) {
0 commit comments