From 17eea383062beb1ad6d9762263c457448e9c6495 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Mon, 12 Aug 2024 16:52:27 +0200
Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Introduce=20SettingsGetterInterface?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ppcp-wc-gateway/src/Settings/Settings.php | 15 +++++++++-
.../src/Settings/SettingsGetterInterface.php | 30 +++++++++++++++++++
2 files changed, 44 insertions(+), 1 deletion(-)
create mode 100644 modules/ppcp-wc-gateway/src/Settings/SettingsGetterInterface.php
diff --git a/modules/ppcp-wc-gateway/src/Settings/Settings.php b/modules/ppcp-wc-gateway/src/Settings/Settings.php
index 25fcb808d..d2d495219 100644
--- a/modules/ppcp-wc-gateway/src/Settings/Settings.php
+++ b/modules/ppcp-wc-gateway/src/Settings/Settings.php
@@ -15,7 +15,7 @@
/**
* Class Settings
*/
-class Settings implements ContainerInterface {
+class Settings implements SettingsGetterInterface, ContainerInterface {
const KEY = 'woocommerce-ppcp-settings';
const CONNECTION_TAB_ID = 'ppcp-connection';
@@ -103,6 +103,19 @@ public function has( $id ) {
return array_key_exists( $id, $this->settings );
}
+ /**
+ * {@inheritDoc}
+ *
+ * Replaces `$settings->has() ? $settings->get() : $default` chains.
+ */
+ public function get_value( string $key, $default = null ) {
+ try {
+ return $this->get( $key );
+ } catch ( NotFoundException $e ) {
+ return $default;
+ }
+ }
+
/**
* Sets a value.
*
diff --git a/modules/ppcp-wc-gateway/src/Settings/SettingsGetterInterface.php b/modules/ppcp-wc-gateway/src/Settings/SettingsGetterInterface.php
new file mode 100644
index 000000000..877fd47f5
--- /dev/null
+++ b/modules/ppcp-wc-gateway/src/Settings/SettingsGetterInterface.php
@@ -0,0 +1,30 @@
+