From 9b1ded7968eb6d67a63efefa7df4607e54561dc3 Mon Sep 17 00:00:00 2001 From: Anthony Bellancourt Date: Tue, 21 Jan 2025 17:21:53 +0100 Subject: [PATCH] allow to manually define the auth token for client and settings --- src/Client.php | 10 ++++++++-- src/Collection.php | 4 +++- src/Settings.php | 5 +++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Client.php b/src/Client.php index 30cae1d..c379513 100644 --- a/src/Client.php +++ b/src/Client.php @@ -5,6 +5,7 @@ namespace Pb; class Client { private string $url; + private string $token = ''; public function __construct(string $url) { @@ -13,11 +14,16 @@ class Client public function collection(string $collection): Collection { - return new Collection($this->url ,$collection); + return new Collection($this->url ,$collection, $this->token); } public function settings(): Settings { - return new Settings($this->url); + return new Settings($this->url, $this->token); + } + + public function setAuthToken(string $token): void + { + $this->token = $token; } } diff --git a/src/Collection.php b/src/Collection.php index 5b1a96d..d875a46 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -25,11 +25,13 @@ class Collection /** * @param string $url * @param string $collection + * @param string $token */ - public function __construct(string $url, string $collection) + public function __construct(string $url, string $collection, string $token) { $this->url = $url; $this->collection = $collection; + self::$token = $token; } /** diff --git a/src/Settings.php b/src/Settings.php index c5d8666..878c36a 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -19,11 +19,12 @@ class Settings /** * @param string $url - * @param string $collection + * @param string $token */ - public function __construct(string $url) + public function __construct(string $url, string $token) { $this->url = $url; + self::$token = $token; } public function authAsAdmin(string $email, string $password): void