From b36508a0bd29f16077a9b8563076a456e8408903 Mon Sep 17 00:00:00 2001 From: aB0t Date: Tue, 24 Oct 2023 10:36:35 +0200 Subject: [PATCH] update 2023-10-24 10:36:32 --- .../README.md | 25 ++++++- .../code.php | 72 +++++++++++++++++-- .../code.power | 71 +++++++++++++++++- .../README.md | 8 +++ .../code.php | 14 +++- .../code.power | 13 +++- .../code.php | 2 +- .../code.power | 2 +- .../README.md | 11 ++- .../code.php | 24 ++++++- .../code.power | 23 +++++- .../code.php | 2 +- .../code.power | 2 +- 13 files changed, 250 insertions(+), 19 deletions(-) diff --git a/src/3d7af7a2-dabe-4111-b5fd-c5bfa8755469/README.md b/src/3d7af7a2-dabe-4111-b5fd-c5bfa8755469/README.md index 0f412ad..341b0b5 100644 --- a/src/3d7af7a2-dabe-4111-b5fd-c5bfa8755469/README.md +++ b/src/3d7af7a2-dabe-4111-b5fd-c5bfa8755469/README.md @@ -14,8 +14,12 @@ abstract Api #Orange { # Http $http # Uri $uri # Response $response + # ?string $url + # ?string $token + __construct(Http $http, Uri $uri, ...) - + load_(?string $url = null, ?string $token = null) : void + + load_(?string $url = null, ?string $token = null, ...) : void + + reset_() : void + + api() : string } note right of Api::__construct @@ -34,6 +38,25 @@ note right of Api::load_ since: 3.2.0 return: void + + arguments: + ?string $url = null + ?string $token = null + bool $backup = true +end note + +note right of Api::reset_ + Reset to previous toke, url it set + + since: 3.2.0 + return: void +end note + +note right of Api::api + Get the API url + + since: 3.2.0 + return: string end note @enduml diff --git a/src/3d7af7a2-dabe-4111-b5fd-c5bfa8755469/code.php b/src/3d7af7a2-dabe-4111-b5fd-c5bfa8755469/code.php index 912af82..ecd5787 100644 --- a/src/3d7af7a2-dabe-4111-b5fd-c5bfa8755469/code.php +++ b/src/3d7af7a2-dabe-4111-b5fd-c5bfa8755469/code.php @@ -48,6 +48,22 @@ abstract class Api */ protected Response $response; + /** + * The Url string + * + * @var string|null + * @since 3.2.0 + */ + protected ?string $url = null; + + /** + * The token string + * + * @var string|null + * @since 3.2.0 + */ + protected ?string $token = null; + /** * Constructor. * @@ -67,14 +83,31 @@ abstract class Api /** * Load/Reload API. * - * @param string|null $url The url. - * @param token|null $token The token. + * @param string|null $url The url. + * @param token|null $token The token. + * @param bool $backup The backup swapping switch. * * @return void * @since 3.2.0 **/ - public function load_(?string $url = null, ?string $token = null) + public function load_(?string $url = null, ?string $token = null, bool $backup = true): void { + // we keep the old values + // so we can reset after our call + // for the rest of the container + if ($backup) + { + if ($url !== null) + { + $this->url = $this->uri->getUrl(); + } + + if ($token !== null) + { + $this->token = $this->http->getToken(); + } + } + if ($url !== null) { $this->uri->setUrl($url); @@ -85,6 +118,37 @@ abstract class Api $this->http->setToken($token); } } - + + /** + * Reset to previous toke, url it set + * + * @return void + * @since 3.2.0 + **/ + public function reset_(): void + { + if ($this->url !== null) + { + $this->uri->setUrl($this->url); + $this->url = null; + } + + if ($this->token !== null) + { + $this->http->setToken($this->token); + $this->token = null; + } + } + + /** + * Get the API url + * + * @return string + * @since 3.2.0 + **/ + public function api() + { + return $this->uri->api(); + } } diff --git a/src/3d7af7a2-dabe-4111-b5fd-c5bfa8755469/code.power b/src/3d7af7a2-dabe-4111-b5fd-c5bfa8755469/code.power index ce6ddc1..483a11c 100644 --- a/src/3d7af7a2-dabe-4111-b5fd-c5bfa8755469/code.power +++ b/src/3d7af7a2-dabe-4111-b5fd-c5bfa8755469/code.power @@ -22,6 +22,22 @@ */ protected Response $response; + /** + * The Url string + * + * @var string|null + * @since 3.2.0 + */ + protected ?string $url = null; + + /** + * The token string + * + * @var string|null + * @since 3.2.0 + */ + protected ?string $token = null; + /** * Constructor. * @@ -41,14 +57,31 @@ /** * Load/Reload API. * - * @param string|null $url The url. - * @param token|null $token The token. + * @param string|null $url The url. + * @param token|null $token The token. + * @param bool $backup The backup swapping switch. * * @return void * @since 3.2.0 **/ - public function load_(?string $url = null, ?string $token = null) + public function load_(?string $url = null, ?string $token = null, bool $backup = true): void { + // we keep the old values + // so we can reset after our call + // for the rest of the container + if ($backup) + { + if ($url !== null) + { + $this->url = $this->uri->getUrl(); + } + + if ($token !== null) + { + $this->token = $this->http->getToken(); + } + } + if ($url !== null) { $this->uri->setUrl($url); @@ -59,3 +92,35 @@ $this->http->setToken($token); } } + + /** + * Reset to previous toke, url it set + * + * @return void + * @since 3.2.0 + **/ + public function reset_(): void + { + if ($this->url !== null) + { + $this->uri->setUrl($this->url); + $this->url = null; + } + + if ($this->token !== null) + { + $this->http->setToken($this->token); + $this->token = null; + } + } + + /** + * Get the API url + * + * @return string + * @since 3.2.0 + **/ + public function api() + { + return $this->uri->api(); + } \ No newline at end of file diff --git a/src/61e813c6-a872-4f55-8078-198241170e80/README.md b/src/61e813c6-a872-4f55-8078-198241170e80/README.md index 2e1caf7..c1f57a2 100644 --- a/src/61e813c6-a872-4f55-8078-198241170e80/README.md +++ b/src/61e813c6-a872-4f55-8078-198241170e80/README.md @@ -18,6 +18,7 @@ class Uri << (F,LightGreen) >> #RoyalBlue { + get(string $path) : JoomlaUri + api() : string + setUrl(string $url) : void + + getUrl() : ?string - setEndpoint(string $endpoint) : void - setVersion(string $version) : void } @@ -58,6 +59,13 @@ example: https://git.vdm.dev return: void end note +note right of Uri::getUrl + Get the URL of the API + + since: 3.2.0 + return: ?string +end note + note right of Uri::setEndpoint Set the endpoint of the API diff --git a/src/61e813c6-a872-4f55-8078-198241170e80/code.php b/src/61e813c6-a872-4f55-8078-198241170e80/code.php index 406caec..daa3add 100644 --- a/src/61e813c6-a872-4f55-8078-198241170e80/code.php +++ b/src/61e813c6-a872-4f55-8078-198241170e80/code.php @@ -110,6 +110,17 @@ final class Uri $this->url = $url; } + /** + * Get the URL of the API + * + * @return string|null + * @since 3.2.0 + **/ + public function getUrl(): ?string + { + return $this->url ?? null; + } + /** * Set the endpoint of the API * @@ -134,7 +145,6 @@ final class Uri private function setVersion($version) { $this->version = $version; - } - + } } diff --git a/src/61e813c6-a872-4f55-8078-198241170e80/code.power b/src/61e813c6-a872-4f55-8078-198241170e80/code.power index 48a0eac..402bbd8 100644 --- a/src/61e813c6-a872-4f55-8078-198241170e80/code.power +++ b/src/61e813c6-a872-4f55-8078-198241170e80/code.power @@ -86,6 +86,17 @@ $this->url = $url; } + /** + * Get the URL of the API + * + * @return string|null + * @since 3.2.0 + **/ + public function getUrl(): ?string + { + return $this->url ?? null; + } + /** * Set the endpoint of the API * @@ -110,4 +121,4 @@ private function setVersion($version) { $this->version = $version; - } + } \ No newline at end of file diff --git a/src/71acf8d6-32b8-4173-8277-eb9cda29fd64/code.php b/src/71acf8d6-32b8-4173-8277-eb9cda29fd64/code.php index ca1d6f3..a4299c6 100644 --- a/src/71acf8d6-32b8-4173-8277-eb9cda29fd64/code.php +++ b/src/71acf8d6-32b8-4173-8277-eb9cda29fd64/code.php @@ -57,7 +57,7 @@ class Gitea implements ServiceProviderInterface $gitea_url = $container->get('Config')->get('custom_gitea_url'); // only load this if we have a custom URL set - if ($add_gitea_url == 2 && is_string($gitea_url) && strpos($gitea_url, 'http') !== false) + if ($add_gitea_url == 2 && !empty($gitea_url) && strpos($gitea_url, 'http') !== false) { return new Uri($gitea_url); } diff --git a/src/71acf8d6-32b8-4173-8277-eb9cda29fd64/code.power b/src/71acf8d6-32b8-4173-8277-eb9cda29fd64/code.power index feaf3e3..903eb38 100644 --- a/src/71acf8d6-32b8-4173-8277-eb9cda29fd64/code.power +++ b/src/71acf8d6-32b8-4173-8277-eb9cda29fd64/code.power @@ -30,7 +30,7 @@ $gitea_url = $container->get('Config')->get('custom_gitea_url'); // only load this if we have a custom URL set - if ($add_gitea_url == 2 && is_string($gitea_url) && strpos($gitea_url, 'http') !== false) + if ($add_gitea_url == 2 && !empty($gitea_url) && strpos($gitea_url, 'http') !== false) { return new Uri($gitea_url); } diff --git a/src/ce40b3d2-226c-4a64-b116-c19455822be1/README.md b/src/ce40b3d2-226c-4a64-b116-c19455822be1/README.md index 7b259c0..e5c8f59 100644 --- a/src/ce40b3d2-226c-4a64-b116-c19455822be1/README.md +++ b/src/ce40b3d2-226c-4a64-b116-c19455822be1/README.md @@ -13,7 +13,8 @@ @startuml class Http << (F,LightGreen) >> #RoyalBlue { + __construct(?string $token) - + setToken(string $token) + + setToken(string $token) : void + + getToken() : ?string } note right of Http::__construct @@ -26,6 +27,14 @@ note right of Http::setToken Change the Token. since: 3.2.0 + return: void +end note + +note right of Http::getToken + Get the Token. + + since: 3.2.0 + return: ?string end note @enduml diff --git a/src/ce40b3d2-226c-4a64-b116-c19455822be1/code.php b/src/ce40b3d2-226c-4a64-b116-c19455822be1/code.php index 7f0b817..6c5b3c6 100644 --- a/src/ce40b3d2-226c-4a64-b116-c19455822be1/code.php +++ b/src/ce40b3d2-226c-4a64-b116-c19455822be1/code.php @@ -23,6 +23,14 @@ use Joomla\Registry\Registry; */ final class Http extends JoomlaHttp { + /** + * The token + * + * @var string + * @since 3.2.0 + */ + protected string $_token_; // to avoid collusions (but allow swapping) + /** * Constructor. * @@ -45,6 +53,7 @@ final class Http extends JoomlaHttp if (is_string($token)) { $config['headers']['Authorization'] = 'token ' . $token; + $this->_token_ = $token; } $options = new Registry($config); @@ -60,7 +69,7 @@ final class Http extends JoomlaHttp * * @since 3.2.0 **/ - public function setToken(string $token) + public function setToken(string $token): void { // get the current headers $headers = (array) $this->getOption('headers', [ @@ -70,9 +79,20 @@ final class Http extends JoomlaHttp // add the token $headers['Authorization'] = 'token ' . $token; + $this->_token_ = $token; $this->setOption('headers', $headers); } - + + /** + * Get the Token. + * + * @return string|null + * @since 3.2.0 + **/ + public function getToken(): ?string + { + return $this->_token_ ?? null; + } } diff --git a/src/ce40b3d2-226c-4a64-b116-c19455822be1/code.power b/src/ce40b3d2-226c-4a64-b116-c19455822be1/code.power index 9ea3730..0e1e9af 100644 --- a/src/ce40b3d2-226c-4a64-b116-c19455822be1/code.power +++ b/src/ce40b3d2-226c-4a64-b116-c19455822be1/code.power @@ -1,3 +1,11 @@ + /** + * The token + * + * @var string + * @since 3.2.0 + */ + protected string $_token_; // to avoid collusions (but allow swapping) + /** * Constructor. * @@ -20,6 +28,7 @@ if (is_string($token)) { $config['headers']['Authorization'] = 'token ' . $token; + $this->_token_ = $token; } $options = new Registry($config); @@ -35,7 +44,7 @@ * * @since 3.2.0 **/ - public function setToken(string $token) + public function setToken(string $token): void { // get the current headers $headers = (array) $this->getOption('headers', [ @@ -45,6 +54,18 @@ // add the token $headers['Authorization'] = 'token ' . $token; + $this->_token_ = $token; $this->setOption('headers', $headers); } + + /** + * Get the Token. + * + * @return string|null + * @since 3.2.0 + **/ + public function getToken(): ?string + { + return $this->_token_ ?? null; + } \ No newline at end of file diff --git a/src/d2e997a1-bbf7-4f28-8a7c-ce5c68061cfe/code.php b/src/d2e997a1-bbf7-4f28-8a7c-ce5c68061cfe/code.php index 8f358a3..7835275 100644 --- a/src/d2e997a1-bbf7-4f28-8a7c-ce5c68061cfe/code.php +++ b/src/d2e997a1-bbf7-4f28-8a7c-ce5c68061cfe/code.php @@ -58,7 +58,7 @@ class Jcb implements ServiceProviderInterface $gitea_url = Helper::getParams('com_componentbuilder')->get('custom_gitea_url'); // only load this if we have a custom URL set - if ($add_gitea_url == 2 && is_string($gitea_url) && strpos($gitea_url, 'http') !== false) + if ($add_gitea_url == 2 && !empty($gitea_url) && strpos($gitea_url, 'http') !== false) { return new Uri($gitea_url); } diff --git a/src/d2e997a1-bbf7-4f28-8a7c-ce5c68061cfe/code.power b/src/d2e997a1-bbf7-4f28-8a7c-ce5c68061cfe/code.power index c1367cc..029c7fc 100644 --- a/src/d2e997a1-bbf7-4f28-8a7c-ce5c68061cfe/code.power +++ b/src/d2e997a1-bbf7-4f28-8a7c-ce5c68061cfe/code.power @@ -30,7 +30,7 @@ $gitea_url = Helper::getParams('com_componentbuilder')->get('custom_gitea_url'); // only load this if we have a custom URL set - if ($add_gitea_url == 2 && is_string($gitea_url) && strpos($gitea_url, 'http') !== false) + if ($add_gitea_url == 2 && !empty($gitea_url) && strpos($gitea_url, 'http') !== false) { return new Uri($gitea_url); }