Skip to content

Commit 15dde7e

Browse files
committed
case insensitive properties, case sensitive property name lists
1 parent 5dc8648 commit 15dde7e

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

resources/lib/ObjectClass.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
/**
88
* 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
1111
* value instead of an array
1212
* $entry is a PHPOpenLDAPer\LDAPEntry
1313
* @since 8.3.0
@@ -17,10 +17,29 @@ class ObjectClass
1717
private ?LDAPEntry $entry = null; // define in constructor of child class
1818
protected static array $attributes_array = [];
1919
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+
}
2037

2138
public function __get(string $property): mixed
2239
{
2340
assert(!is_null($this->entry));
41+
$this->ensureAttributeListsValidated();
42+
$property = strtolower($property);
2443
if (in_array($property, static::$attributes_array, true)) {
2544
return $this->entry->getAttribute($property);
2645
}
@@ -36,7 +55,10 @@ public function __get(string $property): mixed
3655

3756
public function __isset(string $property): bool
3857
{
58+
$this->ensureAttributeListsValidated();
59+
$property = strtolower($property);
3960
assert(!is_null($this->entry));
61+
$this->assert_attribute_lists_are_lowercase();
4062
if (in_array($property, static::$attributes_array, true)
4163
|| in_array($property, static::$attributes_non_array, true)
4264
) {

0 commit comments

Comments
 (0)