Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
yandexexception.php
1
<?php
2
namespace
Bitrix\Seo\Engine
;
3
4
use
Bitrix\Main\Web
;
5
use
Bitrix\Main\Localization\Loc
;
6
use
Bitrix\Main\Web\Json
;
7
8
Loc::loadMessages
(__DIR__.
'/../../seo_search.php'
);
9
10
class
YandexException
11
extends
\Exception
12
{
13
protected
$code
;
14
protected
$message
;
15
16
protected
$result
;
17
protected
$status
;
18
19
public
function
__construct
($queryResult, \Exception $previous = NULL)
20
{
21
// exception use two classes - new and old. Define them
22
if
($queryResult)
23
{
24
if
($queryResult instanceof \CHTTP)
25
{
26
$this->result = $queryResult->result;
27
$this->status = $queryResult->status;
28
}
29
elseif ($queryResult instanceof Web\
HttpClient
)
30
{
31
$this->result = $queryResult->getResult();
32
$this->status = $queryResult->getStatus();
33
}
34
}
35
36
if
(!$queryResult)
37
{
38
parent::__construct(
'no result'
, 0, $previous);
39
}
40
elseif ($this->
parseError
())
41
{
42
$this->formatMessage();
//format and try translate message
43
parent::__construct($this->message, $this->status, $previous);
44
}
45
else
46
{
47
parent::__construct($this->result, $this->status, $previous);
48
}
49
}
50
51
public
function
getStatus
()
52
{
53
return
$this->status
;
54
}
55
56
protected
function
parseError
()
57
{
58
$matches = array();
59
// old style dbg: maybe delete? In new webmaster API this format not using already
60
if
(preg_match(
"/<error code=\"([^\"]+)\"><message>([^<]+)<\/message><\/error>/"
, $this->result, $matches))
61
{
62
$this->code = $matches[1];
63
$this->message = $matches[2];
64
65
// Try translate error. If unknown error - write as is
66
$codeTranslated =
Loc::getMessage
(
'YANDEX_ERROR__'
.str_replace(
' '
,
'_'
,ToUpper($this->code)));
67
$messageTranslated =
Loc::getMessage
(
'YANDEX_ERROR__'
.str_replace(
' '
,
'_'
,ToUpper($this->message)));
68
$this->code = ($codeTranslated <>
''
) ? $codeTranslated :
$this->code
;
69
$this->message = ($messageTranslated <>
''
) ? $messageTranslated :
$this->message
;
70
71
return
true
;
72
}
73
74
// new style
75
if
($resultArray = Json::decode($this->result))
76
{
77
if
(array_key_exists(
'error_code'
, $resultArray))
78
$this->code = $resultArray[
"error_code"
];
79
if
(array_key_exists(
'error_message'
, $resultArray))
80
$this->message = $resultArray[
"error_message"
];
81
82
return
true
;
83
}
84
85
return
false
;
86
}
87
88
private
function
formatMessage()
89
{
90
$translateString =
Loc::getMessage
(
'SEO_ERROR_'
.$this->code);
91
if
($translateString <>
''
)
92
{
93
$this->message = $translateString.
' ('
.
Loc::getMessage
(
'SEO_ERROR_CODE'
).
': '
.$this->code.
').'
;
94
}
95
else
96
{
97
$this->message = $this->code .
': '
.
$this->message
;
98
}
99
}
100
}
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\Web\HttpClient
Definition
httpclient.php:24
Bitrix\Main\Web\Json
Definition
json.php:11
Bitrix\Seo\Engine\YandexException
Definition
yandexexception.php:12
Bitrix\Seo\Engine\YandexException\$result
$result
Definition
yandexexception.php:16
Bitrix\Seo\Engine\YandexException\__construct
__construct($queryResult, \Exception $previous=NULL)
Definition
yandexexception.php:19
Bitrix\Seo\Engine\YandexException\$status
$status
Definition
yandexexception.php:17
Bitrix\Seo\Engine\YandexException\parseError
parseError()
Definition
yandexexception.php:56
Bitrix\Seo\Engine\YandexException\$code
$code
Definition
yandexexception.php:13
Bitrix\Seo\Engine\YandexException\getStatus
getStatus()
Definition
yandexexception.php:51
Bitrix\Seo\Engine\YandexException\$message
$message
Definition
yandexexception.php:14
Bitrix\Main\Web
Definition
cookie.php:3
Bitrix\Seo\Engine
Definition
bitrix.php:9
modules
seo
lib
engine
yandexexception.php
Создано системой
1.10.0