Use non static logger call

This commit is contained in:
Michael 2023-02-27 07:02:06 +00:00
parent 6e3602591d
commit bd3120d6cb
2 changed files with 14 additions and 6 deletions

View File

@ -168,7 +168,7 @@ class StorageManager
return $data['storage_config']; return $data['storage_config'];
} catch (InternalServerErrorException $exception) { } catch (InternalServerErrorException $exception) {
throw new StorageException(sprintf('Failed calling hook::storage_config for backend %s', $name), $exception); throw new StorageException(sprintf('Failed calling hook::storage_config for backend %s', $name), $exception->__toString());
} }
} }
} }
@ -208,7 +208,7 @@ class StorageManager
$this->backendInstances[$name] = new Type\SystemResource(); $this->backendInstances[$name] = new Type\SystemResource();
break; break;
case Type\ExternalResource::getName(): case Type\ExternalResource::getName():
$this->backendInstances[$name] = new Type\ExternalResource(); $this->backendInstances[$name] = new Type\ExternalResource($this->logger);
break; break;
default: default:
$data = [ $data = [
@ -223,7 +223,7 @@ class StorageManager
$this->backendInstances[$data['name'] ?? $name] = $data['storage']; $this->backendInstances[$data['name'] ?? $name] = $data['storage'];
} catch (InternalServerErrorException $exception) { } catch (InternalServerErrorException $exception) {
throw new StorageException(sprintf('Failed calling hook::storage_instance for backend %s', $name), $exception); throw new StorageException(sprintf('Failed calling hook::storage_instance for backend %s', $name), $exception->__toString());
} }
break; break;
} }

View File

@ -22,12 +22,12 @@
namespace Friendica\Core\Storage\Type; namespace Friendica\Core\Storage\Type;
use Exception; use Exception;
use Friendica\Core\Logger;
use Friendica\Core\Storage\Exception\ReferenceStorageException; use Friendica\Core\Storage\Exception\ReferenceStorageException;
use Friendica\Core\Storage\Capability\ICanReadFromStorage; use Friendica\Core\Storage\Capability\ICanReadFromStorage;
use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Util\HTTPSignature; use Friendica\Util\HTTPSignature;
use Psr\Log\LoggerInterface;
/** /**
* External resource storage class * External resource storage class
@ -39,6 +39,14 @@ class ExternalResource implements ICanReadFromStorage
{ {
const NAME = 'ExternalResource'; const NAME = 'ExternalResource';
/** @var LoggerInterface */
protected $logger;
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
/** /**
* @inheritDoc * @inheritDoc
*/ */
@ -57,11 +65,11 @@ class ExternalResource implements ICanReadFromStorage
try { try {
$fetchResult = HTTPSignature::fetchRaw($data->url, $data->uid, [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE]]); $fetchResult = HTTPSignature::fetchRaw($data->url, $data->uid, [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE]]);
} catch (Exception $exception) { } catch (Exception $exception) {
Logger::notice('URL is invalid', ['url' => $data->url, 'error' => $exception]); $this->logger->notice('URL is invalid', ['url' => $data->url, 'error' => $exception]);
throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference), $exception->getCode(), $exception); throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference), $exception->getCode(), $exception);
} }
if (!empty($fetchResult) && $fetchResult->isSuccess()) { if (!empty($fetchResult) && $fetchResult->isSuccess()) {
Logger::debug('Got picture', ['Content-Type' => $fetchResult->getHeader('Content-Type'), 'uid' => $data->uid, 'url' => $data->url]); $this->logger->debug('Got picture', ['Content-Type' => $fetchResult->getHeader('Content-Type'), 'uid' => $data->uid, 'url' => $data->url]);
return $fetchResult->getBody(); return $fetchResult->getBody();
} else { } else {
if (empty($fetchResult)) { if (empty($fetchResult)) {