Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
Request.php
1
<?php
2
3
namespace
Bitrix\Main\UpdateSystem
;
4
5
use
Bitrix\Main\SystemException
;
6
use
Bitrix\Main\Web\HttpClient
;
7
use
Bitrix\Main\Web\HttpHeaders
;
8
use
Bitrix\Main\Web\Uri
;
9
10
class
Request
11
{
12
private
string
$method =
'POST'
;
13
private
?array $body =
null
;
14
private
Uri
$url;
15
private
HttpClient
$httpClient;
16
17
public
function
__construct
()
18
{
19
$this->httpClient =
new
HttpClient
();
20
$this->httpClient->setVersion(
'1.0'
);
21
}
22
23
public
function
setHeaders
(
HttpHeaders
$headers): void
24
{
25
$this->httpClient->setHeaders($headers->toArray());
26
}
27
28
public
function
setUrl
(
Uri
$url): void
29
{
30
$this->url = $url;
31
}
32
33
public
function
setMethod
(
string
$method): void
34
{
35
$this->method = $method;
36
}
37
38
public
function
setProxy
(array $proxyData): void
39
{
40
if
(
41
isset($proxyData[
'host'
])
42
&& !empty($proxyData[
'host'
])
43
&& isset($proxyData[
'port'
])
44
&& !empty($proxyData[
'port'
])
45
) {
46
$this->httpClient->setProxy(
47
$proxyData[
'host'
],
48
$proxyData[
'port'
],
49
$proxyData[
'user'
] ??
null
,
50
$proxyData[
'password'
] ??
null
,
51
);
52
}
53
}
54
55
public
function
setBody
(array $body): void
56
{
57
$this->body = $body;
58
}
59
64
public
function
send
(): string
65
{
66
$this->url->addParams($this->body);
67
$isSuccess = $this->httpClient->query(
68
$this->method,
69
$this->url->getLocator(),
70
$this->body
71
);
72
73
if
($isSuccess)
74
{
75
return
$this->httpClient->getResult();
76
}
77
else
78
{
79
if
($this->httpClient->getStatus() === 0 && empty($this->httpClient->getError()))
80
{
81
throw
new \Exception(
'Invalid response from host: '
.$this->url->getHost().
' [RS01]'
, 400);
82
}
83
else
84
{
85
throw
new
SystemException
(implode(
'\r\n'
, $this->httpClient->getError()).
' [RS02]'
);
86
}
87
}
88
}
89
}
Bitrix\Main\SystemException
Definition
exception.php:8
Bitrix\Main\UpdateSystem\Request
Definition
Request.php:11
Bitrix\Main\UpdateSystem\Request\__construct
__construct()
Definition
Request.php:17
Bitrix\Main\UpdateSystem\Request\send
send()
Definition
Request.php:64
Bitrix\Main\UpdateSystem\Request\setProxy
setProxy(array $proxyData)
Definition
Request.php:38
Bitrix\Main\UpdateSystem\Request\setMethod
setMethod(string $method)
Definition
Request.php:33
Bitrix\Main\UpdateSystem\Request\setUrl
setUrl(Uri $url)
Definition
Request.php:28
Bitrix\Main\UpdateSystem\Request\setBody
setBody(array $body)
Definition
Request.php:55
Bitrix\Main\UpdateSystem\Request\setHeaders
setHeaders(HttpHeaders $headers)
Definition
Request.php:23
Bitrix\Main\Web\HttpClient
Definition
httpclient.php:24
Bitrix\Main\Web\HttpHeaders
Definition
httpheaders.php:18
Bitrix\Main\Web\Uri
Definition
uri.php:17
Bitrix\Main\UpdateSystem
Definition
ActivationSystem.php:1
modules
main
lib
UpdateSystem
Request.php
Создано системой
1.10.0