1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
handler.php
См. документацию.
1<?php
2
9
10namespace Bitrix\Main\Web\Http;
11
12use Bitrix\Main\Diag;
13use Bitrix\Main\Web\HttpDebug;
14use Psr\Log;
15use Psr\Http\Message\RequestInterface;
16
17abstract class Handler implements Log\LoggerAwareInterface, DebugInterface
18{
19 use Log\LoggerAwareTrait;
21
22 protected bool $waitResponse = true;
23 protected int $bodyLengthMax = 0;
24 protected bool $async = false;
25
26 protected RequestInterface $request;
28 protected $shouldFetchBody = null;
29 protected string $responseHeaders = '';
30 protected ?Response $response = null;
31 private bool $logStarted = false;
32
39 {
40 $this->request = $request;
41 $this->responseBuilder = $responseBuilder;
42
43 if (isset($options['waitResponse']))
44 {
45 $this->waitResponse = (bool)$options['waitResponse'];
46 }
47 if (isset($options['bodyLengthMax']))
48 {
49 $this->bodyLengthMax = (int)$options['bodyLengthMax'];
50 }
51 if (isset($options['async']))
52 {
53 $this->async = (bool)$options['async'];
54 }
55 }
56
60 public function getRequest(): RequestInterface
61 {
62 return $this->request;
63 }
64
68 public function getResponse(): ?Response
69 {
70 return $this->response;
71 }
72
78 public function getLogger()
79 {
80 if ($this->logger === null)
81 {
82 $logger = Diag\Logger::create('main.HttpClient', [$this, $this->request]);
83
84 $this->setLogger($logger ?? new Log\NullLogger());
85 }
86
87 return ($this->logger instanceof Log\NullLogger ? null : $this->logger);
88 }
89
90 public function log(string $logMessage, int $level, array $context = []): void
91 {
92 if (($logger = $this->getLogger()) && ($this->debugLevel & $level))
93 {
94 if (!$this->logStarted)
95 {
96 $this->logStarted = true;
97
98 $headMessage = "\n{delimiter}\n{date} - {host}\n{trace}";
99 $headContext = ['trace' => Diag\Helper::getBackTrace(10, DEBUG_BACKTRACE_IGNORE_ARGS, 5)];
100
101 $logger->debug($headMessage, $headContext);
102 }
103
104 $logger->debug($logMessage, $context);
105 }
106 }
107
108 public function logDiagnostics(): void
109 {
110 if ($this->debugLevel & HttpDebug::DIAGNOSTICS)
111 {
112 $this->log(
113 "\n***TIME connect={connect}, handshake={handshake}, request={request}, total={total}\n",
114 HttpDebug::DIAGNOSTICS,
115 $this->getDiagnostics()
116 );
117 }
118 }
119
120 abstract protected function getDiagnostics(): array;
121
128 public function shouldFetchBody(callable $callback): void
129 {
130 $this->shouldFetchBody = $callback;
131 }
132
133 abstract public function execute(): Response;
134}
static getBackTrace($limit=0, $options=null, $skip=1)
Определения helper.php:26
static create(string $id, $params=[])
Определения logger.php:121
Определения response.php:5
shouldFetchBody(callable $callback)
Определения handler.php:128
log(string $logMessage, int $level, array $context=[])
Определения handler.php:90
RequestInterface $request
Определения handler.php:26
string $responseHeaders
Определения handler.php:29
Response $response
Определения handler.php:30
getResponse()
Определения handler.php:68
bool $async
Определения handler.php:24
bool $waitResponse
Определения handler.php:22
__construct(RequestInterface $request, ResponseBuilderInterface $responseBuilder, array $options=[])
Определения handler.php:38
int $bodyLengthMax
Определения handler.php:23
logDiagnostics()
Определения handler.php:108
ResponseBuilderInterface $responseBuilder
Определения handler.php:27
const DIAGNOSTICS
Определения httpdebug.php:21
$options
Определения commerceml2.php:49
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$context
Определения csv_new_setup.php:223
trait DebugInterfaceTrait
Определения debuginterfacetrait.php:15