add configuration registry

This commit is contained in:
Daniel Seifert 2022-07-04 13:31:12 +02:00
parent 18d9748e64
commit 8411ed0786
Signed by: DanielS
GPG Key ID: 8A7C4C6ED1915C6F
3 changed files with 37 additions and 3 deletions

View File

@ -20,8 +20,10 @@ namespace D3\LinkmobilityClient;
use D3\LinkmobilityClient\Exceptions\ApiException; use D3\LinkmobilityClient\Exceptions\ApiException;
use D3\LinkmobilityClient\Exceptions\ExceptionMessages; use D3\LinkmobilityClient\Exceptions\ExceptionMessages;
use D3\LinkmobilityClient\Request\RequestInterface; use D3\LinkmobilityClient\Request\RequestInterface;
use D3\LinkmobilityClient\ValueObject\ValueObject;
use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Exception\GuzzleException;
use InvalidArgumentException; use InvalidArgumentException;
use phpDocumentor\Reflection\Types\Mixed_;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use RuntimeException; use RuntimeException;
@ -33,6 +35,7 @@ class Client
public $requestClient; public $requestClient;
private $logger; private $logger;
private $configuration = [];
public function __construct(string $accessToken, $apiUrl = false, $client = false) public function __construct(string $accessToken, $apiUrl = false, $client = false)
{ {
@ -125,4 +128,35 @@ class Client
return $this->logger; return $this->logger;
} }
/**
* @param string $name
* @param $configuration
*
* @return $this
*/
public function setConfiguration( string $name, $configuration ): Client
{
$this->configuration[$name] = oxNew(ValueObject::class, $configuration);
return $this;
}
public function hasConfiguration(string $name)
{
return isset($this->configuration[$name]);
}
/**
* @param string $name
*
* @return mixed
*/
public function getConfiguration(string $name)
{
if (false === isset($this->configuration)) {
throw new InvalidArgumentException('configuration '.$name.' is not set');
}
return $this->configuration[$name];
}
} }

View File

@ -137,7 +137,7 @@ abstract class Request implements RequestInterface
Assert::that($this->getOptions())->isArray(); Assert::that($this->getOptions())->isArray();
Assert::that( $this->getRecipientsList() )->isInstanceOf(RecipientsList::class)->notEmpty(); Assert::that( $this->getRecipientsList() )->isInstanceOf(RecipientsList::class)->notEmpty();
Assert::that( $this->getRecipientsList()->getRecipients())->notEmpty('request must contain a recipient'); Assert::that( $this->getRecipientsList()->getRecipients())->notEmpty('request must contain a valid recipient');
Assert::thatAll( $this->getRecipientsList() )->isInstanceOf( Recipient::class )->notEmpty(); Assert::thatAll( $this->getRecipientsList() )->isInstanceOf( Recipient::class )->notEmpty();
// optional properties // optional properties

View File

@ -35,8 +35,8 @@ class RequestFactory
*/ */
const GSM_UCS2 = 'ucs-2'; const GSM_UCS2 = 'ucs-2';
private $message; protected $message;
private $client; protected $client;
public function __construct($message, Client $client) public function __construct($message, Client $client)
{ {