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 @@ +