1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
remotedictionary.php
См. документацию.
1
<?php
8
9
namespace
Bitrix\Rest\Dictionary;
10
11
use Bitrix\Main\Application;
12
use Bitrix\Main\ArgumentException;
13
use Bitrix\Main\Event;
14
use Bitrix\Main\Loader;
15
use Bitrix\Main\Localization\Loc;
16
use Bitrix\Main\Type\Dictionary;
17
use Bitrix\Main\Web\HttpClient;
18
use Bitrix\Main\Web\Json;
19
use Bitrix\Main\Web\Uri;
20
21
class
RemoteDictionary
extends
Dictionary
22
{
23
const
ID
=
'generic'
;
24
25
const
CACHE_TTL
= 86400;
26
const
CACHE_PREFIX
=
'rest_dictionary_v2'
;
27
28
protected
$baseUrl
=
array
(
29
'ru'
=>
'https://www.bitrix24.ru/util/'
,
30
'ua'
=>
'https://www.bitrix24.eu/util/'
,
31
'by'
=>
'https://www.bitrix24.by/util/'
,
32
'in'
=>
'https://www.bitrix24.in/util/'
,
33
'en'
=>
'https://www.bitrix24.com/util/'
,
34
'de'
=>
'https://www.bitrix24.de/util/'
,
35
'kz'
=>
'https://www.bitrix24.kz/util/'
,
36
'br'
=>
'https://www.bitrix24.com.br/util/'
,
37
'pl'
=>
'https://www.bitrix24.pl/util/'
,
38
'fr'
=>
'https://www.bitrix24.fr/util/'
,
39
'la'
=>
'https://www.bitrix24.es/util/'
,
40
'eu'
=>
'https://www.bitrix24.eu/util/'
,
41
'cn'
=>
'https://www.bitrix24.cn/util/'
,
42
'tc'
=>
'https://www.bitrix24.cn/util/'
,
43
'sc'
=>
'https://www.bitrix24.cn/util/'
,
44
'tr'
=>
'https://www.bitrix24.com.tr/util/'
,
45
);
46
protected
$language
=
null
;
47
48
public
function
__construct
()
49
{
50
$this->language = LANGUAGE_ID;
51
52
$values
= $this->
init
();
53
54
parent::__construct(
$values
);
55
}
56
57
public
function
setLanguage
(
$language
)
58
{
59
if
(
$language
!== $this->language)
60
{
61
$this->language =
$language
;
62
$this->
set
($this->
init
());
63
}
64
}
65
66
protected
function
init
()
67
{
68
$managedCache = Application::getInstance()->getManagedCache();
69
if
($managedCache->read(static::CACHE_TTL, $this->getCacheId()))
70
{
71
$dictionary = $managedCache->get($this->
getCacheId
());
72
}
73
else
74
{
75
$dictionary = $this->
load
();
76
77
$managedCache->set($this->
getCacheId
(), $dictionary);
78
}
79
80
$event
=
new
Event
(
'rest'
,
'onRemoteDictionaryLoad'
,
array
(
81
'ID'
=> static::ID,
82
'DICTIONARY'
=> &$dictionary
83
));
84
$event
->send();
85
86
return
$dictionary;
87
}
88
89
protected
function
load
()
90
{
91
$httpClient =
new
HttpClient
();
92
93
$uri
= $this->
getDictionaryUri
();
94
95
$httpResult = $httpClient->get(
$uri
->getLocator());
96
97
try
98
{
99
$result
= Json::decode($httpResult);
100
}
101
catch
(
ArgumentException
$e)
102
{
103
$result
=
null
;
104
}
105
106
return
$result
;
107
}
108
109
protected
function
getCacheId
()
110
{
111
return
static::CACHE_PREFIX.
'/'
.static::ID.
'/'
.
$this->language
;
112
}
113
118
protected
function
getDictionaryUri
()
119
{
120
$lang
= Application::getInstance()->getLicense()->getRegion();
121
122
$baseUrl
= array_key_exists(
$lang
, $this->baseUrl)
123
? $this->baseUrl[
$lang
]
124
: $this->baseUrl[Loc::getDefaultLang(
$lang
)];
125
126
$uri
=
new
Uri
(
$baseUrl
);
127
$uri
->addParams(
array
(
128
'type'
=> static::ID,
129
'lng'
=> $this->language,
130
));
131
132
return
$uri
;
133
}
134
}
Bitrix\Main\ArgumentException
Определения
ArgumentException.php:9
Bitrix\Main\Event
Определения
event.php:5
Bitrix\Main\Type\Dictionary
Определения
dictionary.php:6
Bitrix\Main\Type\Dictionary\$values
$values
Определения
dictionary.php:10
Bitrix\Main\Web\HttpClient
Определения
httpclient.php:24
Bitrix\Main\Web\Uri
Определения
uri.php:17
Bitrix\Rest\Dictionary\RemoteDictionary
Определения
remotedictionary.php:22
Bitrix\Rest\Dictionary\RemoteDictionary\ID
const ID
Определения
remotedictionary.php:23
Bitrix\Rest\Dictionary\RemoteDictionary\__construct
__construct()
Определения
remotedictionary.php:48
Bitrix\Rest\Dictionary\RemoteDictionary\getCacheId
getCacheId()
Определения
remotedictionary.php:109
Bitrix\Rest\Dictionary\RemoteDictionary\$baseUrl
$baseUrl
Определения
remotedictionary.php:28
Bitrix\Rest\Dictionary\RemoteDictionary\init
init()
Определения
remotedictionary.php:66
Bitrix\Rest\Dictionary\RemoteDictionary\load
load()
Определения
remotedictionary.php:89
Bitrix\Rest\Dictionary\RemoteDictionary\$language
$language
Определения
remotedictionary.php:46
Bitrix\Rest\Dictionary\RemoteDictionary\setLanguage
setLanguage($language)
Определения
remotedictionary.php:57
Bitrix\Rest\Dictionary\RemoteDictionary\CACHE_TTL
const CACHE_TTL
Определения
remotedictionary.php:25
Bitrix\Rest\Dictionary\RemoteDictionary\getDictionaryUri
getDictionaryUri()
Определения
remotedictionary.php:118
Bitrix\Rest\Dictionary\RemoteDictionary\CACHE_PREFIX
const CACHE_PREFIX
Определения
remotedictionary.php:26
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$result
$result
Определения
get_property_values.php:14
$uri
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения
urlrewrite.php:61
$lang
if(!defined('SITE_ID')) $lang
Определения
include.php:91
$event
$event
Определения
prolog_after.php:141
bitrix
modules
rest
lib
dictionary
remotedictionary.php
Создано системой
1.14.0