mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Implement a helper to map the settings tab.
This commit is contained in:
parent
619c3b1467
commit
00486f4934
1 changed files with 19 additions and 1 deletions
|
@ -10,6 +10,7 @@ declare( strict_types = 1 );
|
|||
namespace WooCommerce\PayPalCommerce\Compat\Settings;
|
||||
|
||||
use RuntimeException;
|
||||
use WooCommerce\PayPalCommerce\Settings\Data\SettingsModel;
|
||||
use WooCommerce\PayPalCommerce\Settings\Data\StylingSettings;
|
||||
|
||||
/**
|
||||
|
@ -49,17 +50,30 @@ class SettingsMapHelper {
|
|||
*/
|
||||
protected StylingSettingsMapHelper $styling_settings_map_helper;
|
||||
|
||||
/**
|
||||
* A helper for mapping the old/new settings tab settings.
|
||||
*
|
||||
* @var SettingsTabMapHelper
|
||||
*/
|
||||
protected SettingsTabMapHelper $settings_tab_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.
|
||||
* @throws RuntimeException When an old key has multiple mappings.
|
||||
*/
|
||||
public function __construct( array $settings_map, StylingSettingsMapHelper $styling_settings_map_helper ) {
|
||||
public function __construct(
|
||||
array $settings_map,
|
||||
StylingSettingsMapHelper $styling_settings_map_helper,
|
||||
SettingsTabMapHelper $settings_tab_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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -135,6 +149,10 @@ class SettingsMapHelper {
|
|||
switch ( true ) {
|
||||
case $model instanceof StylingSettings:
|
||||
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 ] );
|
||||
|
||||
default:
|
||||
return $this->model_cache[ $model_id ][ $new_key ] ?? null;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue