Use the subscriptions helper in setting helper.

This commit is contained in:
Narek Zakarian 2025-02-20 13:48:17 +04:00
parent a16ad7fef5
commit 127fe41e81
No known key found for this signature in database
GPG key ID: 07AFD7E7A9C164A7
2 changed files with 19 additions and 6 deletions

View file

@ -194,7 +194,8 @@ return array(
return new SettingsMapHelper(
$container->get( 'compat.setting.new-to-old-map' ),
$container->get( 'compat.settings.styling_map_helper' ),
$container->get( 'compat.settings.settings_tab_map_helper' )
$container->get( 'compat.settings.settings_tab_map_helper' ),
$container->get( 'compat.settings.subscription_map_helper' )
);
},
'compat.settings.styling_map_helper' => static function() : StylingSettingsMapHelper {

View file

@ -57,23 +57,33 @@ class SettingsMapHelper {
*/
protected SettingsTabMapHelper $settings_tab_map_helper;
/**
* A helper for mapping old and new subscription settings.
*
* @var SubscriptionSettingsMapHelper
*/
protected SubscriptionSettingsMapHelper $subscription_map_helper;
/**
* Constructor.
*
* @param SettingsMap[] $settings_map A list of settings maps containing key definitions.
* @param StylingSettingsMapHelper $styling_settings_map_helper A helper for mapping the old/new styling settings.
* @param SettingsTabMapHelper $settings_tab_map_helper A helper for mapping the old/new settings tab settings.
* @param SettingsMap[] $settings_map A list of settings maps containing key definitions.
* @param StylingSettingsMapHelper $styling_settings_map_helper A helper for mapping the old/new styling settings.
* @param SettingsTabMapHelper $settings_tab_map_helper A helper for mapping the old/new settings tab settings.
* @param SubscriptionSettingsMapHelper $subscription_map_helper A helper for mapping old and new subscription settings.
* @throws RuntimeException When an old key has multiple mappings.
*/
public function __construct(
array $settings_map,
StylingSettingsMapHelper $styling_settings_map_helper,
SettingsTabMapHelper $settings_tab_map_helper
SettingsTabMapHelper $settings_tab_map_helper,
SubscriptionSettingsMapHelper $subscription_map_helper
) {
$this->validate_settings_map( $settings_map );
$this->settings_map = $settings_map;
$this->styling_settings_map_helper = $styling_settings_map_helper;
$this->settings_tab_map_helper = $settings_tab_map_helper;
$this->subscription_map_helper = $subscription_map_helper;
}
/**
@ -151,7 +161,9 @@ class SettingsMapHelper {
return $this->styling_settings_map_helper->mapped_value( $old_key, $this->model_cache[ $model_id ] );
case $model instanceof SettingsModel:
return $this->settings_tab_map_helper->mapped_value( $old_key, $this->model_cache[ $model_id ] );
return $old_key === 'subscriptions_mode'
? $this->subscription_map_helper->mapped_value( $old_key, $this->model_cache[ $model_id ] )
: $this->settings_tab_map_helper->mapped_value( $old_key, $this->model_cache[ $model_id ] );
default:
return $this->model_cache[ $model_id ][ $new_key ] ?? null;