mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Implement Container interface for the Settings
This commit is contained in:
parent
bc3234647c
commit
984b0a23e9
2 changed files with 25 additions and 3 deletions
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Inpsyde\PayPalCommerce\WcGateway\Exception;
|
||||
|
||||
use Exception;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class NotFoundException extends Exception implements NotFoundExceptionInterface
|
||||
{
|
||||
|
||||
}
|
|
@ -4,9 +4,11 @@ declare(strict_types=1);
|
|||
|
||||
namespace Inpsyde\PayPalCommerce\WcGateway\Settings;
|
||||
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Exception\NotFoundException;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class Settings
|
||||
class Settings implements ContainerInterface
|
||||
{
|
||||
private $gateway;
|
||||
private $formFields;
|
||||
|
@ -18,8 +20,16 @@ class Settings
|
|||
}
|
||||
|
||||
// phpcs:ignore Inpsyde.CodeQuality.ReturnTypeDeclaration.NoReturnType
|
||||
public function get(string $settingsKey)
|
||||
public function get($id)
|
||||
{
|
||||
return $this->gateway->get_option($settingsKey);
|
||||
if (!$this->has($id)) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
return $this->gateway->get_option($id);
|
||||
}
|
||||
|
||||
public function has($id)
|
||||
{
|
||||
return array_key_exists($id, $this->formFields->fields());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue