ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
ILIAS\LDAP\Server\ServerUrlList Class Reference

Value object representing a list of LDAP server URLs (primary plus fallbacks). More...

+ Inheritance diagram for ILIAS\LDAP\Server\ServerUrlList:
+ Collaboration diagram for ILIAS\LDAP\Server\ServerUrlList:

Public Member Functions

 __construct (array $entries=[])
 
 count ()
 Returns the number of entries (valid and invalid). More...
 
 getConnectionStringAtIndex (int $index)
 Connection string for ldap_connect() at the given index (0 = primary). More...
 
 toString ()
 Convert to stored form (comma-separated string for database and form). More...
 
 __toString ()
 
 getInvalidParts ()
 Entries that could not be parsed as URI (for GUI validation messages). More...
 
 rotate ()
 New list with first entry moved to the end (for persisted fallback rotation). More...
 
 withPrimaryAt (int $index)
 New list with the entry at $index moved to primary (index 0). More...
 
 validUrls ()
 Iterate over valid URL entries only (invalid/raw string entries are skipped). More...
 

Static Public Member Functions

static fromString (string $stored)
 Create from string representation (comma-separated, as stored in DB or form). More...
 

Private Attributes

array $entries
 

Detailed Description

Value object representing a list of LDAP server URLs (primary plus fallbacks).

Each entry is either a valid \ILIAS\Data\URI or a raw string (unparseable).

Definition at line 30 of file ServerUrlList.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\LDAP\Server\ServerUrlList::__construct ( array  $entries = [])
Parameters
list<URI|string>$entries

Definition at line 38 of file ServerUrlList.php.

39 {
40 $this->entries = array_values($entries);
41 }

References ILIAS\LDAP\Server\ServerUrlList\$entries.

Member Function Documentation

◆ __toString()

ILIAS\LDAP\Server\ServerUrlList::__toString ( )

Definition at line 109 of file ServerUrlList.php.

109 : string
110 {
111 return $this->toString();
112 }
toString()
Convert to stored form (comma-separated string for database and form).

References ILIAS\LDAP\Server\ServerUrlList\toString().

+ Here is the call graph for this function:

◆ count()

ILIAS\LDAP\Server\ServerUrlList::count ( )

Returns the number of entries (valid and invalid).

Definition at line 76 of file ServerUrlList.php.

76 : int
77 {
78 return \count($this->entries);
79 }

Referenced by ILIAS\LDAP\Server\ServerUrlList\rotate().

+ Here is the caller graph for this function:

◆ fromString()

static ILIAS\LDAP\Server\ServerUrlList::fromString ( string  $stored)
static

Create from string representation (comma-separated, as stored in DB or form).

Empty string yields an empty list. Does not throw.

Definition at line 47 of file ServerUrlList.php.

47 : self
48 {
49 $stored = trim($stored);
50 if ($stored === '') {
51 return new self([]);
52 }
53
54 $parts = array_map(
55 static fn(string $s): string => trim($s),
56 explode(',', $stored)
57 );
58
59 $entries = [];
60 foreach ($parts as $part) {
61 if ($part === '') {
62 continue;
63 }
64
65 try {
66 $entries[] = new URI($part);
67 } catch (\Throwable) {
68 $entries[] = $part;
69 }
70 }
71
72 return new self($entries);
73 }
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61

References ILIAS\LDAP\Server\ServerUrlList\$entries, and $parts.

Referenced by ilLDAPServer\setUrl(), ILIAS\LDAP\Tests\Server\ServerUrlListTest\testFromStringEmptyYieldsEmptyList(), ILIAS\LDAP\Tests\Server\ServerUrlListTest\testFromStringHostWithoutSchemeStoredAsInvalid(), ILIAS\LDAP\Tests\Server\ServerUrlListTest\testFromStringInvalidPartStoredAsRawAndReportedInGetInvalidParts(), ILIAS\LDAP\Tests\Server\ServerUrlListTest\testFromStringLdapsPreserved(), ILIAS\LDAP\Tests\Server\ServerUrlListTest\testFromStringMixedValidAndInvalid(), ILIAS\LDAP\Tests\Server\ServerUrlListTest\testFromStringMultipleValidUris(), ILIAS\LDAP\Tests\Server\ServerUrlListTest\testFromStringOnlyWhitespaceAndCommasYieldsEmptyList(), ILIAS\LDAP\Tests\Server\ServerUrlListTest\testFromStringSingleValidUri(), ILIAS\LDAP\Tests\Server\ServerUrlListTest\testFromStringSkipsEmptyPartsAfterTrim(), ILIAS\LDAP\Tests\Server\ServerUrlListTest\testGetConnectionStringAtIndexNegativeIndexReturnsEmptyString(), ILIAS\LDAP\Tests\Server\ServerUrlListTest\testGetConnectionStringAtIndexOutOfRangePositiveReturnsEmptyString(), ILIAS\LDAP\Tests\Server\ServerUrlListTest\testGetConnectionStringAtIndexReturnsRawStringForInvalidEntry(), ILIAS\LDAP\Tests\Server\ServerUrlListTest\testRotateEmptyListReturnsSameInstance(), ILIAS\LDAP\Tests\Server\ServerUrlListTest\testRotateWithOneEntryReturnsSameInstance(), ILIAS\LDAP\Tests\Server\ServerUrlListTest\testRotateWithTwoEntriesMovesFirstToEnd(), ILIAS\LDAP\Tests\Server\ServerUrlListTest\testToStringDelegatesToMagicToString(), ILIAS\LDAP\Tests\Server\ServerUrlListTest\testValidUrlsSkipsInvalidParts(), ILIAS\LDAP\Tests\Server\ServerUrlListTest\testValidUrlsYieldsNothingWhenAllInvalid(), ILIAS\LDAP\Tests\Server\ServerUrlListTest\testValidUrlsYieldsOnlyUriInstances(), ILIAS\LDAP\Tests\Server\ServerUrlListTest\testValidUrlsYieldsOriginalIndicesWithPrimaryAtCorrectWithMixedValidAndInvalid(), ILIAS\LDAP\Tests\Server\ServerUrlListTest\testWithPrimaryAtNegativeIndexReturnsSameInstance(), ILIAS\LDAP\Tests\Server\ServerUrlListTest\testWithPrimaryAtOneMovesSecondToFirst(), ILIAS\LDAP\Tests\Server\ServerUrlListTest\testWithPrimaryAtOutOfRangeReturnsSameInstance(), and ILIAS\LDAP\Tests\Server\ServerUrlListTest\testWithPrimaryAtZeroReturnsSameOrder().

+ Here is the caller graph for this function:

◆ getConnectionStringAtIndex()

ILIAS\LDAP\Server\ServerUrlList::getConnectionStringAtIndex ( int  $index)

Connection string for ldap_connect() at the given index (0 = primary).

Returns empty string if index is out of range or negative.

Definition at line 85 of file ServerUrlList.php.

85 : string
86 {
87 if ($index < 0 || !\array_key_exists($index, $this->entries)) {
88 return '';
89 }
90
91 $el = $this->entries[$index];
92
93 return (string) $el;
94 }

◆ getInvalidParts()

ILIAS\LDAP\Server\ServerUrlList::getInvalidParts ( )

Entries that could not be parsed as URI (for GUI validation messages).

Returns
list<string>

Definition at line 119 of file ServerUrlList.php.

119 : array
120 {
121 $invalid = [];
122 foreach ($this->entries as $el) {
123 if (!($el instanceof URI)) {
124 $invalid[] = $el;
125 }
126 }
127
128 return $invalid;
129 }

◆ rotate()

ILIAS\LDAP\Server\ServerUrlList::rotate ( )

New list with first entry moved to the end (for persisted fallback rotation).

Returns this instance unchanged if the list has fewer than two entries.

Definition at line 135 of file ServerUrlList.php.

135 : self
136 {
137 if (\count($this->entries) < 2) {
138 return $this;
139 }
140
141 $rotated = array_merge(
142 \array_slice($this->entries, 1),
143 [$this->entries[0]]
144 );
145
146 return new self($rotated);
147 }
count()
Returns the number of entries (valid and invalid).

References ILIAS\LDAP\Server\ServerUrlList\count().

+ Here is the call graph for this function:

◆ toString()

ILIAS\LDAP\Server\ServerUrlList::toString ( )

Convert to stored form (comma-separated string for database and form).

Definition at line 99 of file ServerUrlList.php.

99 : string
100 {
101 $strings = array_map(
102 static fn(URI|string $el): string => $el instanceof URI ? (string) $el : (string) $el,
103 $this->entries
104 );
105
106 return implode(',', $strings);
107 }

Referenced by ILIAS\LDAP\Server\ServerUrlList\__toString().

+ Here is the caller graph for this function:

◆ validUrls()

ILIAS\LDAP\Server\ServerUrlList::validUrls ( )

Iterate over valid URL entries only (invalid/raw string entries are skipped).

Yields index => URI so that withPrimaryAt(index) correctly moves the connected server to primary.

Returns
Generator<int, URI>

Definition at line 174 of file ServerUrlList.php.

174 : Generator
175 {
176 foreach ($this->entries as $index => $entry) {
177 if ($entry instanceof URI) {
178 yield $index => $entry;
179 }
180 }
181 }

◆ withPrimaryAt()

ILIAS\LDAP\Server\ServerUrlList::withPrimaryAt ( int  $index)

New list with the entry at $index moved to primary (index 0).

Returns this instance unchanged if index is out of range or negative.

Definition at line 153 of file ServerUrlList.php.

153 : self
154 {
155 if ($index < 0 || !\array_key_exists($index, $this->entries)) {
156 return $this;
157 }
158
159 $entry = $this->entries[$index];
160 $rest = array_merge(
161 \array_slice($this->entries, 0, $index),
162 \array_slice($this->entries, $index + 1)
163 );
164
165 return new self(array_merge([$entry], $rest));
166 }

Field Documentation

◆ $entries

array ILIAS\LDAP\Server\ServerUrlList::$entries
private

The documentation for this class was generated from the following file: