Updates PHPSecLib. Fixed connection failure to remote server. Adds overriding of back-folder and git-folder on component level.
This commit is contained in:
@@ -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);
|
||||
@@ -86,6 +119,27 @@ abstract class Api
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
@@ -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,8 +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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
*
|
||||
|
Reference in New Issue
Block a user