From 0728f80281818599020fded6d46f548ce2274c59 Mon Sep 17 00:00:00 2001 From: Philipp Stracker Date: Wed, 12 Feb 2025 21:06:47 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20the=20settingsd?= =?UTF-8?q?ata=20manager=20constructor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/ppcp-settings/services.php | 7 ++---- .../src/Service/SettingsDataManager.php | 22 ++++++++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/modules/ppcp-settings/services.php b/modules/ppcp-settings/services.php index e5ab98d74..9bc845589 100644 --- a/modules/ppcp-settings/services.php +++ b/modules/ppcp-settings/services.php @@ -249,17 +249,14 @@ return array( return new DataSanitizer(); }, 'settings.service.data-manager' => static function ( ContainerInterface $container ) : SettingsDataManager { - $models = array( + return new SettingsDataManager( $container->get( 'settings.data.onboarding' ), $container->get( 'settings.data.general' ), + $container->get( 'settings.data.settings' ), $container->get( 'settings.data.styling' ), $container->get( 'settings.data.payment' ), - $container->get( 'settings.data.settings' ), $container->get( 'settings.data.todos' ), - $container->get( 'settings.data.definition.todos' ), ); - - return new SettingsDataManager( $models ); }, 'settings.ajax.switch_ui' => static function ( ContainerInterface $container ) : SwitchSettingsUiEndpoint { return new SwitchSettingsUiEndpoint( diff --git a/modules/ppcp-settings/src/Service/SettingsDataManager.php b/modules/ppcp-settings/src/Service/SettingsDataManager.php index cb7aa6275..fd01a16ef 100644 --- a/modules/ppcp-settings/src/Service/SettingsDataManager.php +++ b/modules/ppcp-settings/src/Service/SettingsDataManager.php @@ -10,6 +10,7 @@ declare( strict_types = 1 ); namespace WooCommerce\PayPalCommerce\Settings\Service; use WooCommerce\PayPalCommerce\Settings\Data\AbstractDataModel; +use WooCommerce\PayPalCommerce\Settings\Data\OnboardingProfile; /** * Class SettingsDataManager @@ -19,25 +20,36 @@ use WooCommerce\PayPalCommerce\Settings\Data\AbstractDataModel; */ class SettingsDataManager { + /** + * The onboarding profile data model. + * + * @var OnboardingProfile + */ + private OnboardingProfile $onboarding_profile; + /** * Stores a list of all AbstractDataModel instances that are managed by * this service. * * @var AbstractDataModel[] */ - private array $models = array(); + private array $purgeable_models = array(); /** * Constructor. * - * @param array $data_models List of AbstractDataModel instances. + * @param OnboardingProfile $onboarding_profile The onboarding profile model. + * @param array ...$data_models List of additional data models to reset. */ - public function __construct( array $data_models ) { + public function __construct( OnboardingProfile $onboarding_profile, ...$data_models ) { foreach ( $data_models as $data_model ) { if ( $data_model instanceof AbstractDataModel ) { - $this->models[] = $data_model; + $this->purgeable_models[] = $data_model; } } + + $this->purgeable_models[] = $onboarding_profile; + $this->onboarding_profile = $onboarding_profile; } /** @@ -52,7 +64,7 @@ class SettingsDataManager { */ do_action( 'woocommerce_paypal_payments_reset_settings' ); - foreach ( $this->models as $model ) { + foreach ( $this->purgeable_models as $model ) { $model->purge(); }