]> git.mxchange.org Git - friendica.git/commitdiff
Replace Logger with DI::logger() in Util classes
authorArt4 <art4@wlabs.de>
Mon, 13 Jan 2025 12:53:09 +0000 (12:53 +0000)
committerArt4 <art4@wlabs.de>
Mon, 13 Jan 2025 12:53:09 +0000 (12:53 +0000)
src/Util/Crypto.php
src/Util/DateTimeFormat.php
src/Util/HTTPSignature.php
src/Util/Images.php
src/Util/JsonLD.php
src/Util/LDSignature.php
src/Util/Network.php
src/Util/ParseUrl.php
src/Util/Strings.php
src/Util/XML.php

index 8113697639ef96b176f20c28096874b7e34adad0..da4645ea0e294d2e607522589ad37fdb24dd9c70 100644 (file)
@@ -8,7 +8,6 @@
 namespace Friendica\Util;
 
 use Friendica\Core\Hook;
-use Friendica\Core\Logger;
 use Friendica\DI;
 use phpseclib3\Crypt\PublicKeyLoader;
 
@@ -27,7 +26,7 @@ class Crypto
        public static function rsaSign($data, $key, $alg = 'sha256')
        {
                if (empty($key)) {
-                       Logger::warning('Empty key parameter');
+                       DI::logger()->warning('Empty key parameter');
                }
                openssl_sign($data, $sig, $key, (($alg == 'sha1') ? OPENSSL_ALGO_SHA1 : $alg));
                return $sig;
@@ -43,7 +42,7 @@ class Crypto
        public static function rsaVerify($data, $sig, $key, $alg = 'sha256')
        {
                if (empty($key)) {
-                       Logger::warning('Empty key parameter');
+                       DI::logger()->warning('Empty key parameter');
                }
                return openssl_verify($data, $sig, $key, (($alg == 'sha1') ? OPENSSL_ALGO_SHA1 : $alg));
        }
@@ -80,7 +79,7 @@ class Crypto
                $result = openssl_pkey_new($openssl_options);
 
                if (empty($result)) {
-                       Logger::notice('new_keypair: failed');
+                       DI::logger()->notice('new_keypair: failed');
                        return false;
                }
 
@@ -161,7 +160,7 @@ class Crypto
        private static function encapsulateOther($data, $pubkey, $alg)
        {
                if (!$pubkey) {
-                       Logger::notice('no key. data: '.$data);
+                       DI::logger()->notice('no key. data: '.$data);
                }
                $fn = 'encrypt' . strtoupper($alg);
                if (method_exists(__CLASS__, $fn)) {
@@ -173,7 +172,7 @@ class Crypto
                        // log the offending call so we can track it down
                        if (!openssl_public_encrypt($key, $k, $pubkey)) {
                                $x = debug_backtrace();
-                               Logger::notice('RSA failed', ['trace' => $x[0]]);
+                               DI::logger()->notice('RSA failed', ['trace' => $x[0]]);
                        }
 
                        $result['alg'] = $alg;
@@ -203,7 +202,7 @@ class Crypto
        private static function encapsulateAes($data, $pubkey)
        {
                if (!$pubkey) {
-                       Logger::notice('aes_encapsulate: no key. data: ' . $data);
+                       DI::logger()->notice('aes_encapsulate: no key. data: ' . $data);
                }
 
                $key = random_bytes(32);
@@ -214,7 +213,7 @@ class Crypto
                // log the offending call so we can track it down
                if (!openssl_public_encrypt($key, $k, $pubkey)) {
                        $x = debug_backtrace();
-                       Logger::notice('aes_encapsulate: RSA failed.', ['data' => $x[0]]);
+                       DI::logger()->notice('aes_encapsulate: RSA failed.', ['data' => $x[0]]);
                }
 
                $result['alg'] = 'aes256cbc';
index a8a900fd3695bccf6acd6992a6727de9ad978606..3e10eb1b536a1c804d4a50cf3eaf28fdb90c5c60 100644 (file)
@@ -7,10 +7,10 @@
 
 namespace Friendica\Util;
 
-use Friendica\Core\Logger;
 use DateTime;
 use DateTimeZone;
 use Exception;
+use Friendica\DI;
 
 /**
  * Temporal class
@@ -140,7 +140,7 @@ class DateTimeFormat
                        try {
                                $d = new DateTime(self::fix($s), $from_obj);
                        } catch (\Throwable $e) {
-                               Logger::warning('DateTimeFormat::convert: exception: ' . $e->getMessage());
+                               DI::logger()->warning('DateTimeFormat::convert: exception: ' . $e->getMessage());
                                $d = new DateTime('now', $from_obj);
                        }
                }
index 5f668255caac745f763a63401f5e1c6379ad9272..a544119616748c9cd05c7a71c7b58215d601c7c9 100644 (file)
@@ -7,7 +7,6 @@
 
 namespace Friendica\Util;
 
-use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
 use Friendica\Database\Database;
 use Friendica\Database\DBA;
@@ -72,7 +71,7 @@ class HTTPSignature
                $sig_block = self::parseSigheader($headers['authorization']);
 
                if (!$sig_block) {
-                       Logger::notice('no signature provided.');
+                       DI::logger()->notice('no signature provided.');
                        return $result;
                }
 
@@ -102,7 +101,7 @@ class HTTPSignature
                        $key = $key($sig_block['keyId']);
                }
 
-               Logger::info('Got keyID ' . $sig_block['keyId']);
+               DI::logger()->info('Got keyID ' . $sig_block['keyId']);
 
                if (!$key) {
                        return $result;
@@ -110,7 +109,7 @@ class HTTPSignature
 
                $x = Crypto::rsaVerify($signed_data, $sig_block['signature'], $key, $algorithm);
 
-               Logger::info('verified: ' . $x);
+               DI::logger()->info('verified: ' . $x);
 
                if (!$x) {
                        return $result;
@@ -293,7 +292,7 @@ class HTTPSignature
                $postResult = DI::httpClient()->post($target, $content, $headers, DI::config()->get('system', 'curl_timeout'), HttpClientRequest::ACTIVITYPUB);
                $return_code = $postResult->getReturnCode();
 
-               Logger::info('Transmit to ' . $target . ' returned ' . $return_code);
+               DI::logger()->info('Transmit to ' . $target . ' returned ' . $return_code);
 
                self::setInboxStatus($target, ($return_code >= 200) && ($return_code <= 299));
 
@@ -327,7 +326,7 @@ class HTTPSignature
                        return false;
                }
 
-               Logger::debug('Process directly', ['uid' => $uid, 'target' => $target, 'type' => $type]);
+               DI::logger()->debug('Process directly', ['uid' => $uid, 'target' => $target, 'type' => $type]);
                return Receiver::routeActivities($object_data, $type, true, true, $uid);
        }
 
@@ -371,7 +370,7 @@ class HTTPSignature
                try {
                        $postResult = self::post($data, $target, $owner);
                } catch (\Throwable $th) {
-                       Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                       DI::logger()->notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
                        return false;
                }
                $return_code = $postResult->getReturnCode();
@@ -402,7 +401,7 @@ class HTTPSignature
 
                        $status = DBA::selectFirst('inbox-status', [], ['url' => $url]);
                        if (empty($status)) {
-                               Logger::warning('Unable to insert inbox-status row', $insertFields);
+                               DI::logger()->warning('Unable to insert inbox-status row', $insertFields);
                                return;
                        }
                }
@@ -476,12 +475,12 @@ class HTTPSignature
                try {
                        $curlResult = self::fetchRaw($request, $uid);
                } catch (\Exception $exception) {
-                       Logger::notice('Error fetching url', ['url' => $request, 'exception' => $exception]);
+                       DI::logger()->notice('Error fetching url', ['url' => $request, 'exception' => $exception]);
                        return [];
                }
 
                if (!$curlResult->isSuccess() || empty($curlResult->getBodyString())) {
-                       Logger::debug('Fetching was unsuccessful', ['url' => $request, 'return-code' => $curlResult->getReturnCode(), 'error-number' => $curlResult->getErrorNumber(), 'error' => $curlResult->getError()]);
+                       DI::logger()->debug('Fetching was unsuccessful', ['url' => $request, 'return-code' => $curlResult->getReturnCode(), 'error-number' => $curlResult->getErrorNumber(), 'error' => $curlResult->getError()]);
                        return [];
                }
 
@@ -510,7 +509,7 @@ class HTTPSignature
                }
 
                if (current(explode(';', $contentType)) == 'application/json') {
-                       Logger::notice('Unexpected content type, possibly from a remote system that is not standard compliant.', ['content-type' => $contentType, 'url' => $url]);
+                       DI::logger()->notice('Unexpected content type, possibly from a remote system that is not standard compliant.', ['content-type' => $contentType, 'url' => $url]);
                }
                return false;
        }
@@ -572,7 +571,7 @@ class HTTPSignature
                }
                $return_code = $curlResult->getReturnCode();
 
-               Logger::info('Fetched for user ' . $uid . ' from ' . $request . ' returned ' . $return_code);
+               DI::logger()->info('Fetched for user ' . $uid . ' from ' . $request . ' returned ' . $return_code);
 
                return $curlResult;
        }
@@ -587,14 +586,14 @@ class HTTPSignature
        public static function getKeyIdContact(array $http_headers): array
        {
                if (empty($http_headers['HTTP_SIGNATURE'])) {
-                       Logger::debug('No HTTP_SIGNATURE header', ['header' => $http_headers]);
+                       DI::logger()->debug('No HTTP_SIGNATURE header', ['header' => $http_headers]);
                        return [];
                }
 
                $sig_block = self::parseSigHeader($http_headers['HTTP_SIGNATURE']);
 
                if (empty($sig_block['keyId'])) {
-                       Logger::debug('No keyId', ['sig_block' => $sig_block]);
+                       DI::logger()->debug('No keyId', ['sig_block' => $sig_block]);
                        return [];
                }
 
@@ -614,14 +613,14 @@ class HTTPSignature
        public static function getSigner(string $content, array $http_headers)
        {
                if (empty($http_headers['HTTP_SIGNATURE'])) {
-                       Logger::debug('No HTTP_SIGNATURE header');
+                       DI::logger()->debug('No HTTP_SIGNATURE header');
                        return false;
                }
 
                if (!empty($content)) {
                        $object = json_decode($content, true);
                        if (empty($object)) {
-                               Logger::info('No object');
+                               DI::logger()->info('No object');
                                return false;
                        }
 
@@ -659,7 +658,7 @@ class HTTPSignature
                }
 
                if (empty($sig_block) || empty($sig_block['headers']) || empty($sig_block['keyId'])) {
-                       Logger::info('No headers or keyId');
+                       DI::logger()->info('No headers or keyId');
                        return false;
                }
 
@@ -668,13 +667,13 @@ class HTTPSignature
                        if (array_key_exists($h, $headers)) {
                                $signed_data .= $h . ': ' . $headers[$h] . "\n";
                        } else {
-                               Logger::info('Requested header field not found', ['field' => $h, 'header' => $headers]);
+                               DI::logger()->info('Requested header field not found', ['field' => $h, 'header' => $headers]);
                        }
                }
                $signed_data = rtrim($signed_data, "\n");
 
                if (empty($signed_data)) {
-                       Logger::info('Signed data is empty');
+                       DI::logger()->info('Signed data is empty');
                        return false;
                }
 
@@ -697,18 +696,18 @@ class HTTPSignature
                }
 
                if (empty($algorithm)) {
-                       Logger::info('No algorithm');
+                       DI::logger()->info('No algorithm');
                        return false;
                }
 
                $key = self::fetchKey($sig_block['keyId'], $actor);
                if (empty($key)) {
-                       Logger::info('Empty key');
+                       DI::logger()->info('Empty key');
                        return false;
                }
 
                if (!empty($key['url']) && !empty($key['type']) && ($key['type'] == 'Tombstone')) {
-                       Logger::info('Actor is a tombstone', ['key' => $key]);
+                       DI::logger()->info('Actor is a tombstone', ['key' => $key]);
 
                        if (!Contact::isLocal($key['url'])) {
                                // We now delete everything that we possibly knew from this actor
@@ -718,12 +717,12 @@ class HTTPSignature
                }
 
                if (empty($key['pubkey'])) {
-                       Logger::info('Empty pubkey');
+                       DI::logger()->info('Empty pubkey');
                        return false;
                }
 
                if (!Crypto::rsaVerify($signed_data, $sig_block['signature'], $key['pubkey'], $algorithm)) {
-                       Logger::info('Verification failed', ['signed_data' => $signed_data, 'algorithm' => $algorithm, 'header' => $sig_block['headers'], 'http_headers' => $http_headers]);
+                       DI::logger()->info('Verification failed', ['signed_data' => $signed_data, 'algorithm' => $algorithm, 'header' => $sig_block['headers'], 'http_headers' => $http_headers]);
                        return false;
                }
 
@@ -742,7 +741,7 @@ class HTTPSignature
                        /// @todo add all hashes from the rfc
 
                        if (!empty($hashalg) && base64_encode(hash($hashalg, $content, true)) != $digest[1]) {
-                               Logger::info('Digest does not match');
+                               DI::logger()->info('Digest does not match');
                                return false;
                        }
 
@@ -769,23 +768,23 @@ class HTTPSignature
 
                        // Calculate with a grace period of 60 seconds to avoid slight time differences between the servers
                        if (($created - 60) > $current) {
-                               Logger::notice('Signature created in the future', ['created' => date(DateTimeFormat::MYSQL, $created), 'expired' => date(DateTimeFormat::MYSQL, $expired), 'current' => date(DateTimeFormat::MYSQL, $current)]);
+                               DI::logger()->notice('Signature created in the future', ['created' => date(DateTimeFormat::MYSQL, $created), 'expired' => date(DateTimeFormat::MYSQL, $expired), 'current' => date(DateTimeFormat::MYSQL, $current)]);
                                return false;
                        }
 
                        if ($current > $expired) {
-                               Logger::notice('Signature expired', ['created' => date(DateTimeFormat::MYSQL, $created), 'expired' => date(DateTimeFormat::MYSQL, $expired), 'current' => date(DateTimeFormat::MYSQL, $current)]);
+                               DI::logger()->notice('Signature expired', ['created' => date(DateTimeFormat::MYSQL, $created), 'expired' => date(DateTimeFormat::MYSQL, $expired), 'current' => date(DateTimeFormat::MYSQL, $current)]);
                                return false;
                        }
 
-                       Logger::debug('Valid creation date', ['created' => date(DateTimeFormat::MYSQL, $created), 'expired' => date(DateTimeFormat::MYSQL, $expired), 'current' => date(DateTimeFormat::MYSQL, $current)]);
+                       DI::logger()->debug('Valid creation date', ['created' => date(DateTimeFormat::MYSQL, $created), 'expired' => date(DateTimeFormat::MYSQL, $expired), 'current' => date(DateTimeFormat::MYSQL, $current)]);
                        $hasGoodSignedContent = true;
                }
 
                // Check the content-length when it is part of the signed data
                if (in_array('content-length', $sig_block['headers'])) {
                        if (strlen($content) != $headers['content-length']) {
-                               Logger::info('Content length does not match');
+                               DI::logger()->info('Content length does not match');
                                return false;
                        }
                }
@@ -793,7 +792,7 @@ class HTTPSignature
                // Ensure that the authentication had been done with some content
                // Without this check someone could authenticate with fakeable data
                if (!$hasGoodSignedContent) {
-                       Logger::info('No good signed content');
+                       DI::logger()->info('No good signed content');
                        return false;
                }
 
@@ -815,17 +814,17 @@ class HTTPSignature
 
                $profile = APContact::getByURL($url);
                if (!empty($profile)) {
-                       Logger::info('Taking key from id', ['id' => $id]);
+                       DI::logger()->info('Taking key from id', ['id' => $id]);
                        return ['url' => $url, 'pubkey' => $profile['pubkey'], 'type' => $profile['type']];
                } elseif ($url != $actor) {
                        $profile = APContact::getByURL($actor);
                        if (!empty($profile)) {
-                               Logger::info('Taking key from actor', ['actor' => $actor]);
+                               DI::logger()->info('Taking key from actor', ['actor' => $actor]);
                                return ['url' => $actor, 'pubkey' => $profile['pubkey'], 'type' => $profile['type']];
                        }
                }
 
-               Logger::notice('Key could not be fetched', ['url' => $url, 'actor' => $actor]);
+               DI::logger()->notice('Key could not be fetched', ['url' => $url, 'actor' => $actor]);
                return [];
        }
 }
index f478a0b8b2ab369b74edf439879d163aa0d38f39..804ba73877fc79557f95d4f09df9d6ec99cf8c3b 100644 (file)
@@ -8,7 +8,6 @@
 namespace Friendica\Util;
 
 use Friendica\Core\Hook;
-use Friendica\Core\Logger;
 use Friendica\DI;
 use Friendica\Model\Photo;
 use Friendica\Network\HTTPClient\Client\HttpClientAccept;
@@ -103,7 +102,7 @@ class Images
                        }
                }
 
-               Logger::debug('Undetected mimetype', ['mimetype' => $mimetype]);
+               DI::logger()->debug('Undetected mimetype', ['mimetype' => $mimetype]);
                return 0;
        }
 
@@ -116,7 +115,7 @@ class Images
        public static function getExtensionByImageType(int $type): string
        {
                if (empty($type)) {
-                       Logger::debug('Invalid image type', ['type' => $type]);
+                       DI::logger()->debug('Invalid image type', ['type' => $type]);
                        return '';
                }
 
@@ -201,7 +200,7 @@ class Images
                        return $image['mime'];
                }
 
-               Logger::debug('Undetected mime type', ['image' => $image, 'size' => strlen($image_data)]);
+               DI::logger()->debug('Undetected mime type', ['image' => $image, 'size' => strlen($image_data)]);
 
                return '';
        }
@@ -284,7 +283,7 @@ class Images
                        }
                }
 
-               Logger::debug('Unhandled extension', ['filename' => $filename, 'extension' => $ext]);
+               DI::logger()->debug('Unhandled extension', ['filename' => $filename, 'extension' => $ext]);
                return '';
        }
 
@@ -345,7 +344,7 @@ class Images
                        try {
                                $img_str = DI::httpClient()->fetch($url, HttpClientAccept::IMAGE, 4, '', HttpClientRequest::MEDIAVERIFIER);
                        } catch (\Exception $exception) {
-                               Logger::notice('Image is invalid', ['url' => $url, 'exception' => $exception]);
+                               DI::logger()->notice('Image is invalid', ['url' => $url, 'exception' => $exception]);
                                return [];
                        }
                }
index fc91bcd0b63f07e6e1cddaa08efed169fede2260..833de559d7461a87f1781feb5b25d3bb64dace24 100644 (file)
@@ -8,7 +8,6 @@
 namespace Friendica\Util;
 
 use Friendica\Core\Cache\Enum\Duration;
-use Friendica\Core\Logger;
 use Exception;
 use Friendica\Core\System;
 use Friendica\DI;
@@ -72,7 +71,7 @@ class JsonLD
                                                $url = DI::basePath() . '/static/apschema.jsonld';
                                                break;
                                        default:
-                                               Logger::info('Got url', ['url' => $url]);
+                                               DI::logger()->info('Got url', ['url' => $url]);
                                                break;
                                }
                }
@@ -89,7 +88,7 @@ class JsonLD
                }
 
                if ($recursion > 5) {
-                       Logger::error('jsonld bomb detected at: ' . $url);
+                       DI::logger()->error('jsonld bomb detected at: ' . $url);
                        System::exit();
                }
 
@@ -127,9 +126,9 @@ class JsonLD
                                $messages[] = $currentException->getMessage();
                        } while ($currentException = $currentException->getPrevious());
 
-                       Logger::notice('JsonLD normalize error', ['messages' => $messages]);
-                       Logger::info('JsonLD normalize error', ['trace' => $e->getTraceAsString()]);
-                       Logger::debug('JsonLD normalize error', ['jsonobj' => $jsonobj]);
+                       DI::logger()->notice('JsonLD normalize error', ['messages' => $messages]);
+                       DI::logger()->info('JsonLD normalize error', ['trace' => $e->getTraceAsString()]);
+                       DI::logger()->debug('JsonLD normalize error', ['jsonobj' => $jsonobj]);
                }
 
                return $normalized;
@@ -176,18 +175,18 @@ class JsonLD
                        $compacted = jsonld_compact($jsonobj, $context);
                } catch (Exception $e) {
                        $compacted = false;
-                       Logger::notice('compacting error', ['msg' => $e->getMessage(), 'previous' => $e->getPrevious(), 'line' => $e->getLine()]);
+                       DI::logger()->notice('compacting error', ['msg' => $e->getMessage(), 'previous' => $e->getPrevious(), 'line' => $e->getLine()]);
                        if ($logfailed && DI::config()->get('debug', 'ap_log_failure')) {
                                $tempfile = tempnam(System::getTempPath(), 'failed-jsonld');
                                file_put_contents($tempfile, json_encode(['json' => $orig_json, 'msg' => $e->getMessage(), 'previous' => $e->getPrevious()], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
-                               Logger::notice('Failed message stored', ['file' => $tempfile]);
+                               DI::logger()->notice('Failed message stored', ['file' => $tempfile]);
                        }
                }
 
                $json = json_decode(json_encode($compacted, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), true);
 
                if ($json === false) {
-                       Logger::notice('JSON encode->decode failed', ['orig_json' => $orig_json, 'compacted' => $compacted]);
+                       DI::logger()->notice('JSON encode->decode failed', ['orig_json' => $orig_json, 'compacted' => $compacted]);
                        $json = [];
                }
 
@@ -212,7 +211,7 @@ class JsonLD
                        // Workaround for servers with missing context
                        // See issue https://github.com/nextcloud/social/issues/330
                        if (!in_array('https://w3id.org/security/v1', $json['@context'])) {
-                               Logger::debug('Missing security context');
+                               DI::logger()->debug('Missing security context');
                                $json['@context'][] = 'https://w3id.org/security/v1';
                        }
                }
@@ -220,16 +219,16 @@ class JsonLD
                // Issue 14448: Peertube transmits an unexpected type and schema URL.
                array_walk_recursive($json['@context'], function (&$value, $key) {
                        if ($key == '@type' && $value == '@json') {
-                               Logger::debug('"@json" converted to "@id"');
+                               DI::logger()->debug('"@json" converted to "@id"');
                                $value = '@id';
                        }
                        if ($key == 'sc' && $value == 'http://schema.org/') {
-                               Logger::debug('schema.org path fixed');
+                               DI::logger()->debug('schema.org path fixed');
                                $value = 'http://schema.org#';
                        }
                        // Issue 14630: Wordpress Event Bridge uses a URL that cannot be retrieved
                        if (is_int($key) && $value == 'https://schema.org/') {
-                               Logger::debug('https schema.org path fixed');
+                               DI::logger()->debug('https schema.org path fixed');
                                $value = 'https://schema.org/docs/jsonldcontext.json#';
                        }
                });
@@ -237,7 +236,7 @@ class JsonLD
                // Bookwyrm transmits "id" fields with "null", which isn't allowed.
                array_walk_recursive($json, function (&$value, $key) {
                        if ($key == 'id' && is_null($value)) {
-                               Logger::debug('Fixed null id');
+                               DI::logger()->debug('Fixed null id');
                                $value = '';
                        }
                });
index 9d0c08d33b06e9cf03a7fffe18ce9bdcf797aa10..8728915dd057777bea1b394dc1bd42a10750ddc1 100644 (file)
@@ -7,7 +7,7 @@
 
 namespace Friendica\Util;
 
-use Friendica\Core\Logger;
+use Friendica\DI;
 use Friendica\Model\APContact;
 
 /**
@@ -55,7 +55,7 @@ class LDSignature
                $dhash = self::hash(self::signableData($data));
 
                $x = Crypto::rsaVerify($ohash . $dhash, base64_decode($data['signature']['signatureValue']), $pubkey);
-               Logger::info('LD-verify', ['verified' => (int)$x, 'actor' => $profile['url']]);
+               DI::logger()->info('LD-verify', ['verified' => (int)$x, 'actor' => $profile['url']]);
 
                if (empty($x)) {
                        return false;
index 60f4bbab238b188194e315e2923b08a5057b5242..a9c14779c7674a3fe3f1cbad80fa8d15536d5a2f 100644 (file)
@@ -8,7 +8,6 @@
 namespace Friendica\Util;
 
 use Friendica\Core\Hook;
-use Friendica\Core\Logger;
 use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Network\HTTPClient\Client\HttpClientAccept;
@@ -79,13 +78,13 @@ class Network
                                try {
                                        $curlResult = DI::httpClient()->get($url, HttpClientAccept::DEFAULT, $options);
                                } catch (\Exception $e) {
-                                       Logger::notice('Got exception', ['code' => $e->getCode(), 'message' => $e->getMessage()]);
+                                       DI::logger()->notice('Got exception', ['code' => $e->getCode(), 'message' => $e->getMessage()]);
                                        return false;
                                }
                        }
 
                        if (!$curlResult->isSuccess()) {
-                               Logger::notice('Url not reachable', ['host' => $host, 'url' => $url]);
+                               DI::logger()->notice('Url not reachable', ['host' => $host, 'url' => $url]);
                                return false;
                        } elseif ($curlResult->isRedirectUrl()) {
                                $url = $curlResult->getRedirectUrl();
@@ -184,7 +183,7 @@ class Network
                try {
                        return self::isUriBlocked(new Uri($url));
                } catch (\Throwable $e) {
-                       Logger::warning('Invalid URL', ['url' => $url]);
+                       DI::logger()->warning('Invalid URL', ['url' => $url]);
                        return false;
                }
        }
@@ -310,7 +309,7 @@ class Network
                        $avatar['url'] = DI::baseUrl() . Contact::DEFAULT_AVATAR_PHOTO;
                }
 
-               Logger::info('Avatar: ' . $avatar['email'] . ' ' . $avatar['url']);
+               DI::logger()->info('Avatar: ' . $avatar['email'] . ' ' . $avatar['url']);
                return $avatar['url'];
        }
 
@@ -508,7 +507,7 @@ class Network
        private static function idnToAscii(string $uri): string
        {
                if (!function_exists('idn_to_ascii')) {
-                       Logger::error('IDN functions are missing.');
+                       DI::logger()->error('IDN functions are missing.');
                        return $uri;
                }
                return idn_to_ascii($uri);
@@ -634,7 +633,7 @@ class Network
                }
 
                if ($sanitized != $url) {
-                       Logger::debug('Link got sanitized', ['url' => $url, 'sanitzed' => $sanitized]);
+                       DI::logger()->debug('Link got sanitized', ['url' => $url, 'sanitzed' => $sanitized]);
                }
                return $sanitized;
        }
@@ -654,7 +653,7 @@ class Network
                try {
                        return new Uri($uri);
                } catch (\Exception $e) {
-                       Logger::debug('Invalid URI', ['code' => $e->getCode(), 'message' => $e->getMessage(), 'uri' => $uri]);
+                       DI::logger()->debug('Invalid URI', ['code' => $e->getCode(), 'message' => $e->getMessage(), 'uri' => $uri]);
                        return null;
                }
        }
@@ -662,10 +661,10 @@ class Network
        /**
         * Remove an Url parameter
         *
-        * @param string $url 
-        * @param string $parameter 
-        * @return string 
-        * @throws MalformedUriException 
+        * @param string $url
+        * @param string $parameter
+        * @return string
+        * @throws MalformedUriException
         */
        public static function removeUrlParameter(string $url, string $parameter): string
        {
index 97ecdb977b88522fd3549102ba65adf9676bd37f..8e86007695d82c4fd706099c14fb9997dee1c9d8 100644 (file)
@@ -12,7 +12,6 @@ use DOMXPath;
 use Friendica\Content\Text\HTML;
 use Friendica\Protocol\HTTP\MediaType;
 use Friendica\Core\Hook;
-use Friendica\Core\Logger;
 use Friendica\Database\Database;
 use Friendica\Database\DBA;
 use Friendica\DI;
@@ -68,13 +67,13 @@ class ParseUrl
                        try {
                                $curlResult = DI::httpClient()->get($url, $accept, array_merge([HttpClientOptions::CONTENT_LENGTH => 1000000], $options));
                        } catch (\Throwable $th) {
-                               Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                               DI::logger()->notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
                                return [];
                        }
                }
 
                if (!$curlResult->isSuccess()) {
-                       Logger::debug('Got HTTP Error', ['http error' => $curlResult->getReturnCode(), 'url' => $url]);
+                       DI::logger()->debug('Got HTTP Error', ['http error' => $curlResult->getReturnCode(), 'url' => $url]);
                        return [];
                }
 
@@ -210,7 +209,7 @@ class ParseUrl
                ];
 
                if ($count > 10) {
-                       Logger::warning('Endless loop detected', ['url' => $url]);
+                       DI::logger()->warning('Endless loop detected', ['url' => $url]);
                        return $siteinfo;
                }
 
@@ -219,25 +218,25 @@ class ParseUrl
                } else {
                        $type = self::getContentType($url);
                }
-               Logger::info('Got content-type', ['content-type' => $type, 'url' => $url]);
+               DI::logger()->info('Got content-type', ['content-type' => $type, 'url' => $url]);
                if (!empty($type) && in_array($type[0], ['image', 'video', 'audio'])) {
                        $siteinfo['type'] = $type[0];
                        return $siteinfo;
                }
 
                if ((count($type) >= 2) && (($type[0] != 'text') || ($type[1] != 'html'))) {
-                       Logger::info('Unparseable content-type, quitting here, ', ['content-type' => $type, 'url' => $url]);
+                       DI::logger()->info('Unparseable content-type, quitting here, ', ['content-type' => $type, 'url' => $url]);
                        return $siteinfo;
                }
 
                try {
                        $curlResult = DI::httpClient()->get($url, HttpClientAccept::HTML, [HttpClientOptions::CONTENT_LENGTH => 1000000, HttpClientOptions::REQUEST => HttpClientRequest::SITEINFO]);
                } catch (\Throwable $th) {
-                       Logger::info('Exception when fetching', ['url' => $url, 'code' => $th->getCode(), 'message' => $th->getMessage()]);
+                       DI::logger()->info('Exception when fetching', ['url' => $url, 'code' => $th->getCode(), 'message' => $th->getMessage()]);
                        return $siteinfo;
                }
                if (!$curlResult->isSuccess() || empty($curlResult->getBodyString())) {
-                       Logger::info('Empty body or error when fetching', ['url' => $url, 'success' => $curlResult->isSuccess(), 'code' => $curlResult->getReturnCode()]);
+                       DI::logger()->info('Empty body or error when fetching', ['url' => $url, 'success' => $curlResult->isSuccess(), 'code' => $curlResult->getReturnCode()]);
                        return $siteinfo;
                }
 
@@ -268,7 +267,7 @@ class ParseUrl
                        // See https://github.com/friendica/friendica/issues/5470#issuecomment-418351211
                        $charset = str_ireplace('latin-1', 'latin1', $charset);
 
-                       Logger::info('detected charset', ['charset' => $charset]);
+                       DI::logger()->info('detected charset', ['charset' => $charset]);
                        $body = iconv($charset, 'UTF-8//TRANSLIT', $body);
                }
 
@@ -494,7 +493,7 @@ class ParseUrl
                        }
                }
 
-               Logger::info('Siteinfo fetched', ['url' => $url, 'siteinfo' => $siteinfo]);
+               DI::logger()->info('Siteinfo fetched', ['url' => $url, 'siteinfo' => $siteinfo]);
 
                Hook::callAll('getsiteinfo', $siteinfo);
 
@@ -746,7 +745,7 @@ class ParseUrl
        {
                $type = JsonLD::fetchElement($jsonld, '@type');
                if (empty($type)) {
-                       Logger::info('Empty type', ['url' => $siteinfo['url']]);
+                       DI::logger()->info('Empty type', ['url' => $siteinfo['url']]);
                        return $siteinfo;
                }
 
@@ -823,7 +822,7 @@ class ParseUrl
                        case 'ImageObject':
                                return self::parseJsonLdMediaObject($siteinfo, $jsonld, 'images');
                        default:
-                               Logger::info('Unknown type', ['type' => $type, 'url' => $siteinfo['url']]);
+                               DI::logger()->info('Unknown type', ['type' => $type, 'url' => $siteinfo['url']]);
                                return $siteinfo;
                }
        }
@@ -907,7 +906,7 @@ class ParseUrl
                        $jsonldinfo['author_name'] = trim($jsonld['author']);
                }
 
-               Logger::info('Fetched Author information', ['fetched' => $jsonldinfo]);
+               DI::logger()->info('Fetched Author information', ['fetched' => $jsonldinfo]);
 
                return array_merge($siteinfo, $jsonldinfo);
        }
@@ -978,7 +977,7 @@ class ParseUrl
 
                $jsonldinfo = self::parseJsonLdAuthor($jsonldinfo, $jsonld);
 
-               Logger::info('Fetched article information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]);
+               DI::logger()->info('Fetched article information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]);
 
                return array_merge($siteinfo, $jsonldinfo);
        }
@@ -1018,7 +1017,7 @@ class ParseUrl
 
                $jsonldinfo = self::parseJsonLdAuthor($jsonldinfo, $jsonld);
 
-               Logger::info('Fetched WebPage information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]);
+               DI::logger()->info('Fetched WebPage information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]);
 
                return array_merge($siteinfo, $jsonldinfo);
        }
@@ -1058,7 +1057,7 @@ class ParseUrl
 
                $jsonldinfo = self::parseJsonLdAuthor($jsonldinfo, $jsonld);
 
-               Logger::info('Fetched WebSite information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]);
+               DI::logger()->info('Fetched WebSite information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]);
                return array_merge($siteinfo, $jsonldinfo);
        }
 
@@ -1107,7 +1106,7 @@ class ParseUrl
                        $jsonldinfo['publisher_url'] = Network::sanitizeUrl($content);
                }
 
-               Logger::info('Fetched Organization information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]);
+               DI::logger()->info('Fetched Organization information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]);
                return array_merge($siteinfo, $jsonldinfo);
        }
 
@@ -1146,14 +1145,14 @@ class ParseUrl
 
                $content = JsonLD::fetchElement($jsonld, 'image', 'url', '@type', 'ImageObject');
                if (!empty($content) && !is_string($content)) {
-                       Logger::notice('Unexpected return value for the author image', ['content' => $content]);
+                       DI::logger()->notice('Unexpected return value for the author image', ['content' => $content]);
                }
 
                if (!empty($content) && is_string($content)) {
                        $jsonldinfo['author_img'] = trim($content);
                }
 
-               Logger::info('Fetched Person information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]);
+               DI::logger()->info('Fetched Person information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]);
                return array_merge($siteinfo, $jsonldinfo);
        }
 
@@ -1229,7 +1228,7 @@ class ParseUrl
                        }
                }
 
-               Logger::info('Fetched Media information', ['url' => $siteinfo['url'], 'fetched' => $media]);
+               DI::logger()->info('Fetched Media information', ['url' => $siteinfo['url'], 'fetched' => $media]);
                $siteinfo[$name][] = $media;
                return $siteinfo;
        }
index fbf691879ed45c23f684b193fbd68f772bde6387..60bb83e0d5a8cf27d95f1e6861d6f6c6c6bed2a9 100644 (file)
@@ -8,7 +8,7 @@
 namespace Friendica\Util;
 
 use Friendica\Content\ContactSelector;
-use Friendica\Core\Logger;
+use Friendica\DI;
 use ParagonIE\ConstantTime\Base64;
 
 /**
@@ -498,7 +498,7 @@ class Strings
                );
 
                if (is_null($return)) {
-                       Logger::notice('Received null value from preg_replace_callback', ['text' => $text, 'regex' => $regex, 'blocks' => $blocks, 'executionId' => $executionId]);
+                       DI::logger()->notice('Received null value from preg_replace_callback', ['text' => $text, 'regex' => $regex, 'blocks' => $blocks, 'executionId' => $executionId]);
                }
 
                $text = $callback($return ?? $text) ?? '';
index 52a1d9f3bf3456cbee6acf3e972e1b8583050197..8cf0e86b823e535757f0748e519e749d91bc7c5d 100644 (file)
@@ -11,7 +11,7 @@ use DOMDocument;
 use DOMElement;
 use DOMNode;
 use DOMXPath;
-use Friendica\Core\Logger;
+use Friendica\DI;
 use SimpleXMLElement;
 
 /**
@@ -256,7 +256,7 @@ class XML
                }
 
                if (!function_exists('xml_parser_create')) {
-                       Logger::error('Xml::toArray: parser function missing');
+                       DI::logger()->error('Xml::toArray: parser function missing');
                        return [];
                }
 
@@ -272,7 +272,7 @@ class XML
                }
 
                if (!$parser) {
-                       Logger::warning('Xml::toArray: xml_parser_create: no resource');
+                       DI::logger()->warning('Xml::toArray: xml_parser_create: no resource');
                        return [];
                }
 
@@ -284,9 +284,9 @@ class XML
                @xml_parser_free($parser);
 
                if (! $xml_values) {
-                       Logger::debug('Xml::toArray: libxml: parse error: ' . $contents);
+                       DI::logger()->debug('Xml::toArray: libxml: parse error: ' . $contents);
                        foreach (libxml_get_errors() as $err) {
-                               Logger::debug('libxml: parse: ' . $err->code . ' at ' . $err->line . ':' . $err->column . ' : ' . $err->message);
+                               DI::logger()->debug('libxml: parse: ' . $err->code . ' at ' . $err->line . ':' . $err->column . ' : ' . $err->message);
                        }
                        libxml_clear_errors();
                        return [];
@@ -436,11 +436,11 @@ class XML
                $x = @simplexml_load_string($s);
                if (!$x) {
                        if (!$suppress_log) {
-                               Logger::error('Error(s) while parsing XML string.');
+                               DI::logger()->error('Error(s) while parsing XML string.');
                                foreach (libxml_get_errors() as $err) {
-                                       Logger::info('libxml error', ['code' => $err->code, 'position' => $err->line . ':' . $err->column, 'message' => $err->message]);
+                                       DI::logger()->info('libxml error', ['code' => $err->code, 'position' => $err->line . ':' . $err->column, 'message' => $err->message]);
                                }
-                               Logger::debug('Erroring XML string', ['xml' => $s]);
+                               DI::logger()->debug('Erroring XML string', ['xml' => $s]);
                        }
                        libxml_clear_errors();
                }