update 2023-10-24 10:36:32
This commit is contained in:
parent
71bd39cb1e
commit
b36508a0bd
|
@ -14,8 +14,12 @@ abstract Api #Orange {
|
||||||
# Http $http
|
# Http $http
|
||||||
# Uri $uri
|
# Uri $uri
|
||||||
# Response $response
|
# Response $response
|
||||||
|
# ?string $url
|
||||||
|
# ?string $token
|
||||||
+ __construct(Http $http, Uri $uri, ...)
|
+ __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
|
note right of Api::__construct
|
||||||
|
@ -34,6 +38,25 @@ note right of Api::load_
|
||||||
|
|
||||||
since: 3.2.0
|
since: 3.2.0
|
||||||
return: void
|
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
|
end note
|
||||||
|
|
||||||
@enduml
|
@enduml
|
||||||
|
|
|
@ -48,6 +48,22 @@ abstract class Api
|
||||||
*/
|
*/
|
||||||
protected Response $response;
|
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.
|
* Constructor.
|
||||||
*
|
*
|
||||||
|
@ -67,14 +83,31 @@ abstract class Api
|
||||||
/**
|
/**
|
||||||
* Load/Reload API.
|
* Load/Reload API.
|
||||||
*
|
*
|
||||||
* @param string|null $url The url.
|
* @param string|null $url The url.
|
||||||
* @param token|null $token The token.
|
* @param token|null $token The token.
|
||||||
|
* @param bool $backup The backup swapping switch.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
* @since 3.2.0
|
* @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)
|
if ($url !== null)
|
||||||
{
|
{
|
||||||
$this->uri->setUrl($url);
|
$this->uri->setUrl($url);
|
||||||
|
@ -85,6 +118,37 @@ abstract class Api
|
||||||
$this->http->setToken($token);
|
$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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,22 @@
|
||||||
*/
|
*/
|
||||||
protected Response $response;
|
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.
|
* Constructor.
|
||||||
*
|
*
|
||||||
|
@ -41,14 +57,31 @@
|
||||||
/**
|
/**
|
||||||
* Load/Reload API.
|
* Load/Reload API.
|
||||||
*
|
*
|
||||||
* @param string|null $url The url.
|
* @param string|null $url The url.
|
||||||
* @param token|null $token The token.
|
* @param token|null $token The token.
|
||||||
|
* @param bool $backup The backup swapping switch.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
* @since 3.2.0
|
* @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)
|
if ($url !== null)
|
||||||
{
|
{
|
||||||
$this->uri->setUrl($url);
|
$this->uri->setUrl($url);
|
||||||
|
@ -59,3 +92,35 @@
|
||||||
$this->http->setToken($token);
|
$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();
|
||||||
|
}
|
|
@ -18,6 +18,7 @@ class Uri << (F,LightGreen) >> #RoyalBlue {
|
||||||
+ get(string $path) : JoomlaUri
|
+ get(string $path) : JoomlaUri
|
||||||
+ api() : string
|
+ api() : string
|
||||||
+ setUrl(string $url) : void
|
+ setUrl(string $url) : void
|
||||||
|
+ getUrl() : ?string
|
||||||
- setEndpoint(string $endpoint) : void
|
- setEndpoint(string $endpoint) : void
|
||||||
- setVersion(string $version) : void
|
- setVersion(string $version) : void
|
||||||
}
|
}
|
||||||
|
@ -58,6 +59,13 @@ example: https://git.vdm.dev
|
||||||
return: void
|
return: void
|
||||||
end note
|
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
|
note right of Uri::setEndpoint
|
||||||
Set the endpoint of the API
|
Set the endpoint of the API
|
||||||
|
|
||||||
|
|
|
@ -110,6 +110,17 @@ final class Uri
|
||||||
$this->url = $url;
|
$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
|
* Set the endpoint of the API
|
||||||
*
|
*
|
||||||
|
@ -134,7 +145,6 @@ final class Uri
|
||||||
private function setVersion($version)
|
private function setVersion($version)
|
||||||
{
|
{
|
||||||
$this->version = $version;
|
$this->version = $version;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,6 +86,17 @@
|
||||||
$this->url = $url;
|
$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
|
* Set the endpoint of the API
|
||||||
*
|
*
|
||||||
|
@ -110,4 +121,4 @@
|
||||||
private function setVersion($version)
|
private function setVersion($version)
|
||||||
{
|
{
|
||||||
$this->version = $version;
|
$this->version = $version;
|
||||||
}
|
}
|
|
@ -57,7 +57,7 @@ class Gitea implements ServiceProviderInterface
|
||||||
$gitea_url = $container->get('Config')->get('custom_gitea_url');
|
$gitea_url = $container->get('Config')->get('custom_gitea_url');
|
||||||
|
|
||||||
// only load this if we have a custom URL set
|
// 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);
|
return new Uri($gitea_url);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
$gitea_url = $container->get('Config')->get('custom_gitea_url');
|
$gitea_url = $container->get('Config')->get('custom_gitea_url');
|
||||||
|
|
||||||
// only load this if we have a custom URL set
|
// 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);
|
return new Uri($gitea_url);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,8 @@
|
||||||
@startuml
|
@startuml
|
||||||
class Http << (F,LightGreen) >> #RoyalBlue {
|
class Http << (F,LightGreen) >> #RoyalBlue {
|
||||||
+ __construct(?string $token)
|
+ __construct(?string $token)
|
||||||
+ setToken(string $token)
|
+ setToken(string $token) : void
|
||||||
|
+ getToken() : ?string
|
||||||
}
|
}
|
||||||
|
|
||||||
note right of Http::__construct
|
note right of Http::__construct
|
||||||
|
@ -26,6 +27,14 @@ note right of Http::setToken
|
||||||
Change the Token.
|
Change the Token.
|
||||||
|
|
||||||
since: 3.2.0
|
since: 3.2.0
|
||||||
|
return: void
|
||||||
|
end note
|
||||||
|
|
||||||
|
note right of Http::getToken
|
||||||
|
Get the Token.
|
||||||
|
|
||||||
|
since: 3.2.0
|
||||||
|
return: ?string
|
||||||
end note
|
end note
|
||||||
|
|
||||||
@enduml
|
@enduml
|
||||||
|
|
|
@ -23,6 +23,14 @@ use Joomla\Registry\Registry;
|
||||||
*/
|
*/
|
||||||
final class Http extends JoomlaHttp
|
final class Http extends JoomlaHttp
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* The token
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 3.2.0
|
||||||
|
*/
|
||||||
|
protected string $_token_; // to avoid collusions (but allow swapping)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
|
@ -45,6 +53,7 @@ final class Http extends JoomlaHttp
|
||||||
if (is_string($token))
|
if (is_string($token))
|
||||||
{
|
{
|
||||||
$config['headers']['Authorization'] = 'token ' . $token;
|
$config['headers']['Authorization'] = 'token ' . $token;
|
||||||
|
$this->_token_ = $token;
|
||||||
}
|
}
|
||||||
|
|
||||||
$options = new Registry($config);
|
$options = new Registry($config);
|
||||||
|
@ -60,7 +69,7 @@ final class Http extends JoomlaHttp
|
||||||
*
|
*
|
||||||
* @since 3.2.0
|
* @since 3.2.0
|
||||||
**/
|
**/
|
||||||
public function setToken(string $token)
|
public function setToken(string $token): void
|
||||||
{
|
{
|
||||||
// get the current headers
|
// get the current headers
|
||||||
$headers = (array) $this->getOption('headers', [
|
$headers = (array) $this->getOption('headers', [
|
||||||
|
@ -70,9 +79,20 @@ final class Http extends JoomlaHttp
|
||||||
|
|
||||||
// add the token
|
// add the token
|
||||||
$headers['Authorization'] = 'token ' . $token;
|
$headers['Authorization'] = 'token ' . $token;
|
||||||
|
$this->_token_ = $token;
|
||||||
|
|
||||||
$this->setOption('headers', $headers);
|
$this->setOption('headers', $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Token.
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @since 3.2.0
|
||||||
|
**/
|
||||||
|
public function getToken(): ?string
|
||||||
|
{
|
||||||
|
return $this->_token_ ?? null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,11 @@
|
||||||
|
/**
|
||||||
|
* The token
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 3.2.0
|
||||||
|
*/
|
||||||
|
protected string $_token_; // to avoid collusions (but allow swapping)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
|
@ -20,6 +28,7 @@
|
||||||
if (is_string($token))
|
if (is_string($token))
|
||||||
{
|
{
|
||||||
$config['headers']['Authorization'] = 'token ' . $token;
|
$config['headers']['Authorization'] = 'token ' . $token;
|
||||||
|
$this->_token_ = $token;
|
||||||
}
|
}
|
||||||
|
|
||||||
$options = new Registry($config);
|
$options = new Registry($config);
|
||||||
|
@ -35,7 +44,7 @@
|
||||||
*
|
*
|
||||||
* @since 3.2.0
|
* @since 3.2.0
|
||||||
**/
|
**/
|
||||||
public function setToken(string $token)
|
public function setToken(string $token): void
|
||||||
{
|
{
|
||||||
// get the current headers
|
// get the current headers
|
||||||
$headers = (array) $this->getOption('headers', [
|
$headers = (array) $this->getOption('headers', [
|
||||||
|
@ -45,6 +54,18 @@
|
||||||
|
|
||||||
// add the token
|
// add the token
|
||||||
$headers['Authorization'] = 'token ' . $token;
|
$headers['Authorization'] = 'token ' . $token;
|
||||||
|
$this->_token_ = $token;
|
||||||
|
|
||||||
$this->setOption('headers', $headers);
|
$this->setOption('headers', $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Token.
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @since 3.2.0
|
||||||
|
**/
|
||||||
|
public function getToken(): ?string
|
||||||
|
{
|
||||||
|
return $this->_token_ ?? null;
|
||||||
|
}
|
|
@ -58,7 +58,7 @@ class Jcb implements ServiceProviderInterface
|
||||||
$gitea_url = Helper::getParams('com_componentbuilder')->get('custom_gitea_url');
|
$gitea_url = Helper::getParams('com_componentbuilder')->get('custom_gitea_url');
|
||||||
|
|
||||||
// only load this if we have a custom URL set
|
// 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);
|
return new Uri($gitea_url);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
$gitea_url = Helper::getParams('com_componentbuilder')->get('custom_gitea_url');
|
$gitea_url = Helper::getParams('com_componentbuilder')->get('custom_gitea_url');
|
||||||
|
|
||||||
// only load this if we have a custom URL set
|
// 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);
|
return new Uri($gitea_url);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue