Skip to content

Commit

Permalink
New database prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
xtrime-ru committed Nov 19, 2023
1 parent d2ae22a commit df5a7b8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
48 changes: 24 additions & 24 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function addSession(string $session, array $settings = []): API
Files::getSessionSettings($session),
);

$settingsObject = self::getSettingsFromArray($settings);
$settingsObject = self::getSettingsFromArray($session, $settings);

$instance = new API($file, $settingsObject);
$instance->updateSettings($settingsObject);
Expand Down Expand Up @@ -159,8 +159,7 @@ public static function getWrapper(API $madelineProto): APIWrapper
return $wrapper;
}

private static function getSettingsFromArray(array $settings, SettingsAbstract $settingsObject = new Settings()): SettingsAbstract {

private static function getSettingsFromArray(string $session, array $settings, SettingsAbstract $settingsObject = new Settings()): SettingsAbstract {
foreach ($settings as $key => $value) {
if (is_array($value)) {
if ($key === 'db' && isset($value['type'])) {
Expand All @@ -171,10 +170,12 @@ private static function getSettingsFromArray(array $settings, SettingsAbstract $
'redis' => new Settings\Database\Redis(),
};
$settingsObject->setDb($type);
if ($value['type'] === 'memory') {
self::getSettingsFromArray([], $type);

if ($type instanceof Settings\Database\Memory) {
self::getSettingsFromArray($session, [], $type);
} else {
self::getSettingsFromArray($value[$value['type']], $type);
$type->setEphemeralFilesystemPrefix($session);
self::getSettingsFromArray($session, $value[$value['type']], $type);
}

unset($value[$value['type']], $value['type'],);
Expand All @@ -184,7 +185,7 @@ private static function getSettingsFromArray(array $settings, SettingsAbstract $
}

$method = 'get' . ucfirst(str_replace('_', '', ucwords($key, '_')));
self::getSettingsFromArray($value, $settingsObject->$method());
self::getSettingsFromArray($session, $value, $settingsObject->$method());
} else {
$method = 'set' . ucfirst(str_replace('_', '', ucwords($key, '_')));
$settingsObject->$method($value);
Expand Down

0 comments on commit df5a7b8

Please sign in to comment.