Skip to content

Commit c1b22a6

Browse files
Merge pull request #172 from gp-lnuff/4.x
Let append and prepend be set to null without throwing an exception
2 parents 4428d1f + 9c4c578 commit c1b22a6

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/SelectTree.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ public function prepend(Closure|array|null $prepend = null): static
313313

314314
if (is_array($this->prepend) && isset($this->prepend['name'], $this->prepend['value'])) {
315315
$this->prepend['value'] = (string) $this->prepend['value'];
316+
} else if (is_null($this->prepend)){
317+
# Avoid throwing an exception in case $prepend is explicitly set to null, or a Closure evaluates to null.
316318
} else {
317319
throw new InvalidArgumentException('The provided prepend value must be an array with "name" and "value" keys.');
318320
}
@@ -326,6 +328,8 @@ public function append(Closure|array|null $append = null): static
326328

327329
if (is_array($this->append) && isset($this->append['name'], $this->append['value'])) {
328330
$this->append['value'] = (string) $this->append['value'];
331+
} else if (is_null($this->append)) {
332+
// Avoid throwing an exception in case $append is explicitly set to null, or a Closure evaluates to null.
329333
} else {
330334
throw new \InvalidArgumentException('The provided append value must be an array with "name" and "value" keys.');
331335
}

0 commit comments

Comments
 (0)