Skip to content

Commit a220b5c

Browse files
committed
refactor: add property $config
1 parent 09ea35f commit a220b5c

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/Handlers/DatabaseHandler.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use CodeIgniter\Database\BaseBuilder;
66
use CodeIgniter\I18n\Time;
7+
use CodeIgniter\Settings\Config\Settings;
78
use 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

Comments
 (0)