44
55use CodeIgniter \Database \BaseBuilder ;
66use CodeIgniter \I18n \Time ;
7+ use CodeIgniter \Settings \Config \Settings ;
78use RuntimeException ;
89
910/**
@@ -24,12 +25,15 @@ class DatabaseHandler extends ArrayHandler
2425 */
2526 private $ hydrated = [];
2627
28+ private Settings $ config ;
29+
2730 /**
2831 * Stores the configured database table.
2932 */
3033 public function __construct ()
3134 {
32- $ this ->builder = db_connect (config ('Settings ' )->database ['group ' ])->table (config ('Settings ' )->database ['table ' ]);
35+ $ this ->config = config ('Settings ' );
36+ $ this ->builder = db_connect ($ this ->config ->database ['group ' ])->table ($ this ->config ->database ['table ' ]);
3337 }
3438
3539 /**
@@ -97,7 +101,7 @@ public function set(string $class, string $property, $value = null, ?string $con
97101 }
98102
99103 if ($ result !== true ) {
100- throw new RuntimeException (db_connect (config ( ' Settings ' ) ->database ['group ' ])->error ()['message ' ] ?? 'Error writing to the database. ' );
104+ throw new RuntimeException (db_connect ($ this -> config ->database ['group ' ])->error ()['message ' ] ?? 'Error writing to the database. ' );
101105 }
102106
103107 // Update storage
@@ -122,7 +126,7 @@ public function forget(string $class, string $property, ?string $context = null)
122126 ->delete ();
123127
124128 if (! $ result ) {
125- throw new RuntimeException (db_connect (config ( ' Settings ' ) ->database ['group ' ])->error ()['message ' ] ?? 'Error writing to the database. ' );
129+ throw new RuntimeException (db_connect ($ this -> config ->database ['group ' ])->error ()['message ' ] ?? 'Error writing to the database. ' );
126130 }
127131
128132 // Delete from local storage
@@ -160,7 +164,7 @@ private function hydrate(?string $context): void
160164 }
161165
162166 if (is_bool ($ result = $ query ->get ())) {
163- throw new RuntimeException (db_connect (config ( ' Settings ' ) ->database ['group ' ])->error ()['message ' ] ?? 'Error reading from database. ' );
167+ throw new RuntimeException (db_connect ($ this -> config ->database ['group ' ])->error ()['message ' ] ?? 'Error reading from database. ' );
164168 }
165169
166170 foreach ($ result ->getResultObject () as $ row ) {
0 commit comments