1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
httpquery.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Calendar\Sync\Google;
4
5
use Bitrix\Calendar\Sync\Util\RequestLogger;
6
use Bitrix\Main\DB\Exception;
7
use Bitrix\Main\Web\HttpClient;
8
9
class
HttpQuery
10
{
11
private
const
SERVICE_NAME =
'google'
;
15
private
HttpClient
$client;
19
private
?
RequestLogger
$logger =
null
;
20
21
public
function
__construct
(
HttpClient
$client,
int
$userId
,
string
$serviceName =
'google'
)
22
{
23
$this->client = $client;
24
if
(RequestLogger::isEnabled())
25
{
26
$this->logger =
new
RequestLogger
(
$userId
, self::SERVICE_NAME);
27
}
28
}
29
33
public
function
getClient
():
HttpClient
34
{
35
return
$this->client;
36
}
37
45
public
function
query
(
string
$method
,
string
$url
, $body =
null
): void
46
{
47
$this->client->query(
$method
,
$url
, $body);
48
49
if
($this->logger)
50
{
51
$this->logger->write([
52
'requestParams'
=> $body,
53
'url'
=>
$url
,
54
'method'
=>
$method
,
55
'statusCode'
=> $this->client->getStatus(),
56
'response'
=> $this->prepareResponseForDebug($this->client->getResult()),
57
'error'
=> $this->prepareErrorForDebug($this->client->getResult()),
58
]);
59
}
60
}
61
65
public
function
getStatus
(): int
66
{
67
return
$this->client->getStatus();
68
}
69
73
public
function
getResult
(): string
74
{
75
return
$this->client->getResult();
76
}
77
84
public
function
post
(
string
$url
, $body =
null
): void
85
{
86
$this->
query
(HttpClient::HTTP_POST,
$url
, $body);
87
}
88
95
public
function
get
(
string
$url
, $body =
null
): void
96
{
97
$this->
query
(HttpClient::HTTP_GET,
$url
, $body);
98
}
99
106
public
function
delete
(
string
$url
, $body =
null
): void
107
{
108
$this->
query
(HttpClient::HTTP_DELETE,
$url
, $body);
109
}
110
116
public
function
put
(
string
$url
, $body =
null
): void
117
{
118
$this->
query
(HttpClient::HTTP_PUT,
$url
, $body);
119
}
120
125
private
function
prepareResponseForDebug(
$response
): string
126
{
127
if
($this->client->getStatus() >= 300)
128
{
129
return
''
;
130
}
131
132
try
133
{
134
$response
=
\Bitrix\Main\Web\Json::decode
(
$response
);
135
}
136
catch
(\Exception $e){}
137
138
if
(!
$response
|| !is_array(
$response
))
139
{
140
return
''
;
141
}
142
143
$result
=
''
;
144
145
foreach
(
$response
as
$key
=> $value)
146
{
147
if
(is_string($value))
148
{
149
$result
.=
"{$key}:{$value}; "
;
150
}
151
elseif
(is_array($value))
152
{
153
$result
.=
"{$key}:"
;
154
foreach
($value as $valueKey => $valueValue)
155
{
156
$valueValue = (is_array($valueValue)) ? json_encode($valueValue) : $valueValue;
157
$result
.=
"{$valueKey}:{$valueValue}, "
;
158
}
159
$result
.=
"; "
;
160
}
161
}
162
163
return
$result
;
164
}
165
169
private
function
prepareErrorForDebug(
$response
): string
170
{
171
try
172
{
173
$response
= \Bitrix\Main\Web\Json::decode(
$response
);
174
}
175
catch
(\Exception $e){}
176
177
if
(
178
(!
$response
|| !is_array(
$response
))
179
|| ($this->client->getStatus() < 400)
180
)
181
{
182
return
''
;
183
}
184
185
return
$response
[
'error'
][
'code'
] .
" "
.
$response
[
'error'
][
'message'
] .
"; "
;
186
}
187
}
$userId
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения
check_mail.php:18
Bitrix\Calendar\Sync\Google\HttpQuery
Определения
httpquery.php:10
Bitrix\Calendar\Sync\Google\HttpQuery\getClient
getClient()
Определения
httpquery.php:33
Bitrix\Calendar\Sync\Google\HttpQuery\post
post(string $url, $body=null)
Определения
httpquery.php:84
Bitrix\Calendar\Sync\Google\HttpQuery\__construct
__construct(HttpClient $client, int $userId, string $serviceName='google')
Определения
httpquery.php:21
Bitrix\Calendar\Sync\Google\HttpQuery\put
put(string $url, $body=null)
Определения
httpquery.php:116
Bitrix\Calendar\Sync\Google\HttpQuery\getStatus
getStatus()
Определения
httpquery.php:65
Bitrix\Calendar\Sync\Google\HttpQuery\getResult
getResult()
Определения
httpquery.php:73
Bitrix\Calendar\Sync\Google\HttpQuery\query
query(string $method, string $url, $body=null)
Определения
httpquery.php:45
Bitrix\Calendar\Sync\Util\RequestLogger
Определения
requestlogger.php:11
Bitrix\Main\Web\HttpClient
Определения
httpclient.php:24
Bitrix\Main\Web\Json\decode
static decode($data)
Определения
json.php:50
$result
$result
Определения
get_property_values.php:14
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$key
if(empty($signedUserToken)) $key
Определения
quickway.php:257
$response
$response
Определения
result.php:21
$method
$method
Определения
index.php:27
$url
$url
Определения
iframe.php:7
bitrix
modules
calendar
lib
sync
google
httpquery.php
Создано системой
1.14.0