Skip to content

Commit ed730bd

Browse files
Refactor toArray method in Config class
The method has been revised to first assign its output to a variable and checking if `settings` is not empty before merging its array output to the result. This ensures the data returned is correct even when `settings` is empty.
1 parent 51ac72a commit ed730bd

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/Config.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,13 +593,19 @@ public function removeAccessLog(): bool
593593
*/
594594
#[Override] public function toArray(): array
595595
{
596-
return [
596+
$data = [
597597
'listeners' => $this->mapConfigObjectToArray($this->listeners),
598598
'routes' => $this->mapConfigObjectToArray($this->routes),
599599
'applications' => $this->mapConfigObjectToArray($this->applications),
600600
'upstreams' => $this->mapConfigObjectToArray($this->upstreams),
601-
'settings' => $this->settings->toArray()
601+
'settings' => $this->settings?->toArray()
602602
];
603+
604+
if (!empty($this->settings)) {
605+
$data = array_merge($data, $this->settings->toArray());
606+
}
607+
608+
return $data;
603609
}
604610

605611
/**

0 commit comments

Comments
 (0)