Implement Container interface for the Settings

This commit is contained in:
Mészáros Róbert 2020-04-09 14:35:19 +03:00
parent bc3234647c
commit 984b0a23e9
2 changed files with 25 additions and 3 deletions

View file

@ -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
{
}

View file

@ -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());
}
}