Introduce HTPPRequest DI call and constructor

This commit is contained in:
nupplaPhil 2020-03-04 22:11:01 +01:00 committed by Hypolite Petovan
parent 5344efef71
commit 9d00e4f1bc
2 changed files with 54 additions and 23 deletions

View file

@ -323,6 +323,18 @@ abstract class DI
return self::$dice->create(Model\Storage\IStorage::class); return self::$dice->create(Model\Storage\IStorage::class);
} }
//
// "Network" namespace
//
/**
* @return Network\HTTPRequest
*/
public static function httpRequest()
{
return self::$dice->create(Network\HTTPRequest::class);
}
// //
// "Repository" namespace // "Repository" namespace
// //

View file

@ -21,16 +21,37 @@
namespace Friendica\Network; namespace Friendica\Network;
use Friendica\App;
use Friendica\Core\Config\IConfig;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\DI; use Friendica\DI;
use Friendica\Util\Network; use Friendica\Util\Network;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
/** /**
* Performs HTTP requests to a given URL * Performs HTTP requests to a given URL
*/ */
class HTTPRequest class HTTPRequest
{ {
/** @var LoggerInterface */
private $logger;
/** @var Profiler */
private $profiler;
/** @var IConfig */
private $config;
/** @var string */
private $userAgent;
public function __construct(LoggerInterface $logger, Profiler $profiler, IConfig $config, App $a)
{
$this->logger = $logger;
$this->profiler = $profiler;
$this->config = $config;
$this->userAgent = $a->getUserAgent();
}
/** /**
* fetches an URL. * fetches an URL.
* *
@ -54,8 +75,6 @@ class HTTPRequest
{ {
$stamp1 = microtime(true); $stamp1 = microtime(true);
$a = DI::app();
if (strlen($url) > 1000) { if (strlen($url) > 1000) {
Logger::log('URL is longer than 1000 characters. Callstack: ' . System::callstack(20), Logger::DEBUG); Logger::log('URL is longer than 1000 characters. Callstack: ' . System::callstack(20), Logger::DEBUG);
return CurlResult::createErrorCurl(substr($url, 0, 200)); return CurlResult::createErrorCurl(substr($url, 0, 200));