forked from friendica/friendica-addons
Merge pull request #1198 from nupplaphil/feat/httpclient_restructuring
Paradigm Restructuring Part 3 - Logger HTTPClient
This commit is contained in:
commit
0bef8af9e3
|
@ -21,7 +21,7 @@ use Friendica\Model\Group;
|
||||||
use Friendica\Model\Item;
|
use Friendica\Model\Item;
|
||||||
use Friendica\Model\Post;
|
use Friendica\Model\Post;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
use Friendica\Network\HTTPClientOptions;
|
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
|
||||||
use Friendica\Protocol\Activity;
|
use Friendica\Protocol\Activity;
|
||||||
use Friendica\Protocol\ActivityNamespace;
|
use Friendica\Protocol\ActivityNamespace;
|
||||||
use Friendica\Core\Config\Util\ConfigFileLoader;
|
use Friendica\Core\Config\Util\ConfigFileLoader;
|
||||||
|
@ -1537,7 +1537,7 @@ function pumpio_fetchallcomments(App $a, $uid, $id)
|
||||||
|
|
||||||
function pumpio_reachable($url)
|
function pumpio_reachable($url)
|
||||||
{
|
{
|
||||||
return DI::httpClient()->get($url, [HTTPClientOptions::TIMEOUT => 10])->isSuccess();
|
return DI::httpClient()->get($url, [HttpClientOptions::TIMEOUT => 10])->isSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -6,8 +6,8 @@ use Exception;
|
||||||
use Friendica\Core\Storage\Capability\ICanWriteToStorage;
|
use Friendica\Core\Storage\Capability\ICanWriteToStorage;
|
||||||
use Friendica\Core\Storage\Exception\ReferenceStorageException;
|
use Friendica\Core\Storage\Exception\ReferenceStorageException;
|
||||||
use Friendica\Core\Storage\Exception\StorageException;
|
use Friendica\Core\Storage\Exception\StorageException;
|
||||||
use Friendica\Network\HTTPClientOptions;
|
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
|
||||||
use Friendica\Network\IHTTPClient;
|
use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ class WebDav implements ICanWriteToStorage
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $url;
|
private $url;
|
||||||
|
|
||||||
/** @var IHTTPClient */
|
/** @var ICanSendHttpRequests */
|
||||||
private $client;
|
private $client;
|
||||||
|
|
||||||
/** @var LoggerInterface */
|
/** @var LoggerInterface */
|
||||||
|
@ -33,12 +33,12 @@ class WebDav implements ICanWriteToStorage
|
||||||
/**
|
/**
|
||||||
* WebDav constructor
|
* WebDav constructor
|
||||||
*
|
*
|
||||||
* @param string $url The full URL to the webdav endpoint (including the subdirectories)
|
* @param string $url The full URL to the webdav endpoint (including the subdirectories)
|
||||||
* @param array $authOptions The authentication options for the http calls ( ['username', 'password', 'auth_type'] )
|
* @param array $authOptions The authentication options for the http calls ( ['username', 'password', 'auth_type'] )
|
||||||
* @param IHTTPClient $client The http client for communicating with the WebDav endpoint
|
* @param ICanSendHttpRequests $client The http client for communicating with the WebDav endpoint
|
||||||
* @param LoggerInterface $logger The standard logging class
|
* @param LoggerInterface $logger The standard logging class
|
||||||
*/
|
*/
|
||||||
public function __construct(string $url, array $authOptions, IHTTPClient $client, LoggerInterface $logger)
|
public function __construct(string $url, array $authOptions, ICanSendHttpRequests $client, LoggerInterface $logger)
|
||||||
{
|
{
|
||||||
$this->client = $client;
|
$this->client = $client;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
|
@ -85,7 +85,7 @@ class WebDav implements ICanWriteToStorage
|
||||||
*/
|
*/
|
||||||
protected function exists(string $uri): bool
|
protected function exists(string $uri): bool
|
||||||
{
|
{
|
||||||
return $this->client->head($uri, [HTTPClientOptions::AUTH => $this->authOptions])->getReturnCode() == 200;
|
return $this->client->head($uri, [HttpClientOptions::AUTH => $this->authOptions])->getReturnCode() == 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -105,9 +105,9 @@ class WebDav implements ICanWriteToStorage
|
||||||
$dom->appendChild($root)->appendChild($prop);
|
$dom->appendChild($root)->appendChild($prop);
|
||||||
|
|
||||||
$opts = [
|
$opts = [
|
||||||
HTTPClientOptions::AUTH => $this->authOptions,
|
HttpClientOptions::AUTH => $this->authOptions,
|
||||||
HTTPClientOptions::HEADERS => ['Depth' => 1, 'Prefer' => 'return-minimal', 'Content-Type' => 'application/xml'],
|
HttpClientOptions::HEADERS => ['Depth' => 1, 'Prefer' => 'return-minimal', 'Content-Type' => 'application/xml'],
|
||||||
HTTPClientOptions::BODY => $dom->saveXML(),
|
HttpClientOptions::BODY => $dom->saveXML(),
|
||||||
];
|
];
|
||||||
|
|
||||||
$response = $this->client->request('propfind', $uri, $opts);
|
$response = $this->client->request('propfind', $uri, $opts);
|
||||||
|
@ -133,7 +133,7 @@ class WebDav implements ICanWriteToStorage
|
||||||
*/
|
*/
|
||||||
protected function mkcol(string $uri): bool
|
protected function mkcol(string $uri): bool
|
||||||
{
|
{
|
||||||
return $this->client->request('mkcol', $uri, [HTTPClientOptions::AUTH => $this->authOptions])
|
return $this->client->request('mkcol', $uri, [HttpClientOptions::AUTH => $this->authOptions])
|
||||||
->getReturnCode() == 200;
|
->getReturnCode() == 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ class WebDav implements ICanWriteToStorage
|
||||||
foreach ($pathParts as $pathPart) {
|
foreach ($pathParts as $pathPart) {
|
||||||
$checkUrl = $this->url . $partURL;
|
$checkUrl = $this->url . $partURL;
|
||||||
if (!empty($partURL) && !$this->hasItems($checkUrl)) {
|
if (!empty($partURL) && !$this->hasItems($checkUrl)) {
|
||||||
$response = $this->client->request('delete', $checkUrl, [HTTPClientOptions::AUTH => $this->authOptions]);
|
$response = $this->client->request('delete', $checkUrl, [HttpClientOptions::AUTH => $this->authOptions]);
|
||||||
|
|
||||||
if (!$response->isSuccess()) {
|
if (!$response->isSuccess()) {
|
||||||
if ($response->getReturnCode() == "404") {
|
if ($response->getReturnCode() == "404") {
|
||||||
|
@ -199,7 +199,7 @@ class WebDav implements ICanWriteToStorage
|
||||||
{
|
{
|
||||||
$file = $this->pathForRef($reference);
|
$file = $this->pathForRef($reference);
|
||||||
|
|
||||||
$response = $this->client->request('get', $this->url . '/' . $file[0], [HTTPClientOptions::AUTH => $this->authOptions]);
|
$response = $this->client->request('get', $this->url . '/' . $file[0], [HttpClientOptions::AUTH => $this->authOptions]);
|
||||||
|
|
||||||
if (!$response->isSuccess()) {
|
if (!$response->isSuccess()) {
|
||||||
throw new ReferenceStorageException(sprintf('Invalid reference %s', $reference));
|
throw new ReferenceStorageException(sprintf('Invalid reference %s', $reference));
|
||||||
|
@ -225,8 +225,8 @@ class WebDav implements ICanWriteToStorage
|
||||||
$this->checkAndCreatePath($file[1]);
|
$this->checkAndCreatePath($file[1]);
|
||||||
|
|
||||||
$opts = [
|
$opts = [
|
||||||
HTTPClientOptions::BODY => $data,
|
HttpClientOptions::BODY => $data,
|
||||||
HTTPClientOptions::AUTH => $this->authOptions,
|
HttpClientOptions::AUTH => $this->authOptions,
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->client->request('put', $this->url . '/' . $file[0], $opts);
|
$this->client->request('put', $this->url . '/' . $file[0], $opts);
|
||||||
|
@ -241,7 +241,7 @@ class WebDav implements ICanWriteToStorage
|
||||||
{
|
{
|
||||||
$file = $this->pathForRef($reference);
|
$file = $this->pathForRef($reference);
|
||||||
|
|
||||||
$response = $this->client->request('delete', $this->url . '/' . $file[0], [HTTPClientOptions::AUTH => $this->authOptions]);
|
$response = $this->client->request('delete', $this->url . '/' . $file[0], [HttpClientOptions::AUTH => $this->authOptions]);
|
||||||
|
|
||||||
if (!$response->isSuccess()) {
|
if (!$response->isSuccess()) {
|
||||||
throw new ReferenceStorageException(sprintf('Invalid reference %s', $reference));
|
throw new ReferenceStorageException(sprintf('Invalid reference %s', $reference));
|
||||||
|
|
|
@ -5,8 +5,8 @@ namespace Friendica\Addon\webdav_storage\src;
|
||||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
use Friendica\Core\Storage\Capability\ICanConfigureStorage;
|
use Friendica\Core\Storage\Capability\ICanConfigureStorage;
|
||||||
use Friendica\Network\HTTPClientOptions;
|
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
|
||||||
use Friendica\Network\IHTTPClient;
|
use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The WebDav Backend Storage configuration class
|
* The WebDav Backend Storage configuration class
|
||||||
|
@ -24,7 +24,7 @@ class WebDavConfig implements ICanConfigureStorage
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $url;
|
private $url;
|
||||||
|
|
||||||
/** @var IHTTPClient */
|
/** @var \Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests */
|
||||||
private $client;
|
private $client;
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
|
@ -46,7 +46,7 @@ class WebDavConfig implements ICanConfigureStorage
|
||||||
return $this->authOptions;
|
return $this->authOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __construct(L10n $l10n, IManageConfigValues $config, IHTTPClient $client)
|
public function __construct(L10n $l10n, IManageConfigValues $config, ICanSendHttpRequests $client)
|
||||||
{
|
{
|
||||||
$this->l10n = $l10n;
|
$this->l10n = $l10n;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
|
@ -138,7 +138,7 @@ class WebDavConfig implements ICanConfigureStorage
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->client->head($url, [HTTPClientOptions::AUTH => $options])->isSuccess()) {
|
if (!$this->client->head($url, [HttpClientOptions::AUTH => $options])->isSuccess()) {
|
||||||
return [
|
return [
|
||||||
'url' => $this->l10n->t('url is either invalid or not reachable'),
|
'url' => $this->l10n->t('url is either invalid or not reachable'),
|
||||||
];
|
];
|
||||||
|
|
|
@ -4,9 +4,9 @@ namespace Friendica\Addon\webdav_storage\tests;
|
||||||
|
|
||||||
use Friendica\Addon\webdav_storage\src\WebDav;
|
use Friendica\Addon\webdav_storage\src\WebDav;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Factory\HTTPClientFactory;
|
use Friendica\Network\HTTPClient\Factory\HTTPClientFactory;
|
||||||
use Friendica\Test\src\Core\Storage\StorageTest;
|
use Friendica\Test\src\Core\Storage\StorageTest;
|
||||||
use Friendica\Util\Logger\VoidLogger;
|
use Friendica\Core\Logger\Type\VoidLogger;
|
||||||
|
|
||||||
/// @todo remove when constant is moved to a class constant
|
/// @todo remove when constant is moved to a class constant
|
||||||
/// Necessary for DB_UPDATE_VERSION constant in case of direct calls, where dbstructure isn't included during the calling process
|
/// Necessary for DB_UPDATE_VERSION constant in case of direct calls, where dbstructure isn't included during the calling process
|
||||||
|
|
Loading…
Reference in a new issue