-
Notifications
You must be signed in to change notification settings - Fork 111
Description
I had to extend the DatabaseSettingStore for some unimportant reasons. So I followed the instructions in the readme and added the a new class:
class CustomDatabaseSettingStore extends Base
{
public function __construct(Connection $connection)
{
parent::__construct(
$connection,
config('settings.table'),
config('settings.keyColumn'),
config('settings.valueColumn')
);
}
// more code here
}and I added the following to my AppServiceProvider:
Setting::extend('customDatabaseSettingStore', function ($app) {
return $app->make(CustomDatabaseSettingStore::class);
});I have caching enabled, but I found the setting cache suspiciously empty. So I checked, and it turns out that caching settings are never set in the custom store, and I think defaults also don't work. These are usually set in SettingsManager::wrapDriver() which is never called.
I had to add the code from wrapDriver() to my custom store:
class CustomDatabaseSettingStore extends Base
{
public function __construct(Connection $connection)
{
parent::__construct(
$connection,
config('settings.table'),
config('settings.keyColumn'),
config('settings.valueColumn')
);
$this->setDefaults(config('settings.defaults'));
if (config('settings.enableCache')) {
$this->setCache(
app()['cache'],
config('settings.cacheTtl'),
config('settings.forgetCacheByWrite')
);
}
}
// more code
}I think, at the very least, the readme should be updated. I was very surprised that this was needed, especially because it is usually handled by the SettingsManager, which I wouldn't have expected to have to look at. I would prefer if wrapDriver() was somehow called for custom drivers, but it would already be helpful if it were public and easily accessible.