Skip to content

Commit

Permalink
Aggiornato DbConfig.php per gestire sottocchiavi nei dati di configur…
Browse files Browse the repository at this point in the history
…azione
  • Loading branch information
inerba committed Mar 13, 2024
1 parent e8f83c5 commit 6c4a8bf
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/DbConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ class DbConfig
*/
public static function get(string $key, mixed $default = null): mixed
{
[$group, $setting] = static::parseKey($key);
[$group, $setting, $subKey] = static::parseKey($key);

$cachename = "db-config.{$group}.{$setting}";

// $default = $default ?? "[{$group}.{$setting}]";

$data = Cache::rememberForever($cachename, fn () => static::fetchConfig($group, $setting));

$value = data_get($data, $setting, $default);
$value = data_get($data, $subKey, $default);

return $value ?? $default;
}
Expand Down Expand Up @@ -74,8 +74,9 @@ protected static function parseKey(string $key): array
$keyParts = explode('.', $key);
$group = array_shift($keyParts);
$setting = $keyParts[0] ?? null;
$subKey = implode('.', $keyParts);

return [$group, $setting];
return [$group, $setting, $subKey];
}

protected static function fetchConfig(string $group, string $setting): array
Expand All @@ -85,7 +86,7 @@ protected static function fetchConfig(string $group, string $setting): array
->where('key', $setting)
->first();

if (! $item) {
if (!$item) {
return [];
}

Expand Down

0 comments on commit 6c4a8bf

Please sign in to comment.