Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Default Settings Repository #3127

Merged
merged 18 commits into from
Oct 31, 2021

Conversation

SychO9
Copy link
Member

@SychO9 SychO9 commented Oct 26, 2021

Fixes #3056
Needed for #3011

Changes proposed in this pull request:

  • Introduces a default settings extender to register setting default values.
  • Deprecates the addSettings migration helper.

Reviewers should focus on:
I don't think we're missing anything about us switching to this approach ?

Necessity

  • Has the problem that is being solved here been clearly explained?
  • If applicable, have various options for solving this problem been considered?
  • For core PRs, does this need to be in core, or could it be in an extension?
  • Are we willing to maintain this for years / potentially forever?

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).
  • Core developer confirmed locally this works as intended.
  • Tests have been added, or are not appropriate here.

Copy link
Member

@askvortsov1 askvortsov1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Radical idea, but alongside this, I think we should consider deprecating the default arguments to get settings. Otherwise, those arguments take on a weird hybrid role between truly being a setting default, and representing "if setting is null, do X". The latter isn't nonsensical, but it can also be done explicitly.

On the other hand, maybe there could be theoretical use cases for overriding the default on individual call sites, although I can't really think of any. But keeping defaults to one place would definitely simplify things.

src/Extend/Settings.php Outdated Show resolved Hide resolved
src/Extend/Settings.php Outdated Show resolved Hide resolved
src/Settings/DefaultSettingsManager.php Outdated Show resolved Hide resolved
src/Settings/MemoryCacheSettingsRepository.php Outdated Show resolved Hide resolved
src/Settings/SettingsServiceProvider.php Outdated Show resolved Hide resolved
src/Settings/SettingsServiceProvider.php Outdated Show resolved Hide resolved
src/Extend/Settings.php Show resolved Hide resolved
src/Settings/DefaultSettingsRepository.php Outdated Show resolved Hide resolved
src/Settings/MemoryCacheSettingsRepository.php Outdated Show resolved Hide resolved
src/Settings/MemoryCacheSettingsRepository.php Outdated Show resolved Hide resolved
src/Settings/MemoryCacheSettingsRepository.php Outdated Show resolved Hide resolved
@SychO9 SychO9 changed the title Register default settings programmatically feat: Default Settings Repository Oct 30, 2021
Copy link
Member

@askvortsov1 askvortsov1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking over this again, there's still one thing I'm unsure about.

There's a difference between a setting not being set (in which case default should be used), and a setting having the value of null (in which case null should be returned). Ideally, our system should be able to distinguish between the two, but because of the current implementation with nullable defaults, the difference between the two is encapsulated within get and not available to the caller. In this PR, you pass the configured default value through the repo layers, which solves the problem, but depends on the default argument that we are hoping to remove.

For v2, when we do remove the argument, we could throw an exception in DatabaseSettingsRepository if the setting is not found. This doesn't depend on the default arg, so it fits well with our plans. It would be a breaking change though, which is why we can't do it now.

src/Settings/DefaultSettingsRepository.php Outdated Show resolved Hide resolved
src/Settings/SettingsServiceProvider.php Outdated Show resolved Hide resolved
@SychO9
Copy link
Member Author

SychO9 commented Oct 31, 2021

There's a difference between a setting not being set (in which case default should be used), and a setting having the value of null (in which case null should be returned). Ideally, our system should be able to distinguish between the two, but because of the current implementation with nullable defaults, the difference between the two is encapsulated within get and not available to the caller. In this PR, you pass the configured default value through the repo layers, which solves the problem, but depends on the default argument that we are hoping to remove.

Good point! hadn't thought of that, and agree with the plan for 2.0

Copy link
Member

@askvortsov1 askvortsov1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really nice now!

@SychO9 SychO9 merged commit fcf23ee into master Oct 31, 2021
@SychO9 SychO9 deleted the sm/3056-programatical-default-setting-values branch October 31, 2021 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Default Settings Via Extender
4 participants