Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
googlesource.php
1
<?php
2
3
namespace
Bitrix\Location\Source\Google
;
4
5
use
Bitrix\Location\Common\Pool
;
6
use
Bitrix\Location\Entity\Source
;
7
use
Bitrix\Location\Repository\Location\IRepository
;
8
use
Bitrix\Location\Common\CachedPool
;
9
use
Bitrix\Main\Data\Cache
;
10
use
Bitrix\Main\EventManager
;
11
use
Bitrix\Main\Web\HttpClient
;
12
use
Bitrix\Main\Config\Option
;
13
use
Bitrix\Main\Loader
;
14
use Bitrix\Fileman;
15
21
class
GoogleSource
extends
Source
22
{
26
public
function
makeRepository
():
IRepository
27
{
28
static
$result =
null
;
29
30
if
(!is_null($result))
31
{
32
return
$result;
33
}
34
35
$httpClient =
new
HttpClient
(
36
[
37
'version'
=>
'1.1'
,
38
'socketTimeout'
=> 30,
39
'streamTimeout'
=> 30,
40
'redirect'
=>
true
,
41
'redirectMax'
=> 5,
42
]
43
);
44
45
$cacheTTL = 2592000;
//month
46
$poolSize = 100;
47
$pool =
new
Pool
($poolSize);
48
49
$cachePool =
new
CachedPool
(
50
$pool,
51
$cacheTTL,
52
'locationSourceGoogleRequester'
,
53
Cache::createInstance(),
54
EventManager::getInstance()
55
);
56
57
$result =
new
Repository
(
58
$this->getBackendKey(),
59
$httpClient,
60
$this,
61
$cachePool
62
);
63
64
return
$result;
65
}
66
70
public
function
getJSParams
(): array
71
{
72
return
[
73
'apiKey'
=> $this->getFrontendKey(),
74
'showPhotos'
=> $this->config->getValue(
'SHOW_PHOTOS_ON_MAP'
),
75
'useGeocodingService'
=> $this->config->getValue(
'USE_GEOCODING_SERVICE'
),
76
];
77
}
78
82
private
function
getBackendKey(): string
83
{
84
$configKey = $this->config->getValue(
'API_KEY_BACKEND'
);
85
if
($configKey)
86
{
87
return
(
string
)$configKey;
88
}
89
90
return
(
string
)Option::get(
'location'
,
'google_map_api_key_backend'
,
''
);
91
}
92
96
private
function
getFrontendKey(): string
97
{
98
$key = $this->config->getValue(
'API_KEY_FRONTEND'
);
99
if
($key)
100
{
101
return
(
string
)$key;
102
}
103
104
$key = Option::get(
'location'
,
'google_map_api_key'
,
''
);
105
if
($key !==
''
)
106
{
107
return
(
string
)$key;
108
}
109
110
if
(Loader::includeModule(
'fileman'
))
111
{
112
$key = Fileman\UserField\Types\AddressType::getApiKey();
113
if
($key !==
''
&& !is_null($key))
114
{
115
return
$key;
116
}
117
}
118
119
return
''
;
120
}
121
127
public
function
convertLang
(
string
$bitrixLang): string
128
{
129
$langMap = [
130
'br'
=>
'pt-BR'
,
// Portuguese (Brazil)
131
'la'
=>
'es'
,
// Spanish
132
'sc'
=>
'zh-CN'
,
// Chinese (Simplified)
133
'tc'
=>
'zh-TW'
,
// Chinese (Traditional)
134
'vn'
=>
'vi'
,
// Vietnamese
135
'ua'
=>
'uk'
,
// Ukrainian
136
];
137
138
return
$langMap[$bitrixLang] ?? $bitrixLang;
139
}
140
141
public
function
isAvailable
(): bool
142
{
143
return
$this->getBackendKey() && $this->getFrontendKey();
144
}
145
}
Bitrix\Location\Common\CachedPool
Definition
cachedpool.php:12
Bitrix\Location\Common\Pool
Definition
pool.php:9
Bitrix\Location\Entity\Source
Definition
source.php:17
Bitrix\Location\Source\Google\GoogleSource
Definition
googlesource.php:22
Bitrix\Location\Source\Google\GoogleSource\convertLang
convertLang(string $bitrixLang)
Definition
googlesource.php:127
Bitrix\Location\Source\Google\GoogleSource\makeRepository
makeRepository()
Definition
googlesource.php:26
Bitrix\Location\Source\Google\GoogleSource\getJSParams
getJSParams()
Definition
googlesource.php:70
Bitrix\Location\Source\Google\GoogleSource\isAvailable
isAvailable()
Definition
googlesource.php:141
Bitrix\Location\Source\Google\Repository
Definition
repository.php:31
Bitrix\Main\Config\Option
Definition
option.php:15
Bitrix\Main\Data\Cache
Definition
cache.php:16
Bitrix\Main\EventManager
Definition
eventmanager.php:15
Bitrix\Main\Loader
Definition
loader.php:12
Bitrix\Main\Web\HttpClient
Definition
httpclient.php:24
Bitrix\Location\Repository\Location\IRepository
Definition
irepository.php:11
Bitrix\Location\Entity\Source
Definition
config.php:3
Bitrix\Location\Source\Google
Definition
configfactory.php:3
modules
location
lib
source
google
googlesource.php
Создано системой
1.10.0