From 9ddffba3d5edee89876dfcee49b8f0de0811e9d4 Mon Sep 17 00:00:00 2001 From: LuukvH Date: Mon, 8 Jul 2024 11:14:18 +0200 Subject: [PATCH] feat: Allow to pass configuration Allow to pass a custom Guzzle configuration to the connection. --- example.php | 2 +- src/Connection.php | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/example.php b/example.php index a9272b4..a06d1e3 100644 --- a/example.php +++ b/example.php @@ -2,7 +2,7 @@ require __DIR__ . '/vendor/autoload.php'; -$access_token = ''; # testing program builder key +$access_token = ''; $connection = new Eduframe\Connection(); diff --git a/src/Connection.php b/src/Connection.php index 6f8b4d0..2439ca9 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -36,6 +36,11 @@ class Connection */ private $client; + /** + * @var Configuration + */ + private $clientConfig; + /** * @var array Middlewares for the Guzzle 6 client */ @@ -46,6 +51,14 @@ class Connection */ private $stage = PRODUCTION; + /** + * Eduframe constructor. + * @param \Eduframe\Connection $connection + */ + public function __construct(array $clientConfig = []) { + $this->clientConfig = $clientConfig; + } + /** * @return Client */ @@ -59,13 +72,15 @@ private function client() { $handlerStack->push($middleWare); } - $args = [ + $defaultClientConfig = [ 'http_errors' => true, 'handler' => $handlerStack, 'expect' => false, ]; - $this->client = new Client($args); + $clientConfig = array_merge($defaultClientConfig, $this->clientConfig); + + $this->client = new Client($clientConfig); return $this->client; }