Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
osmsource.php
1
<?php
2
3
namespace
Bitrix\Location\Source\Osm
;
4
5
use
Bitrix\Location\Entity\Source
;
6
use
Bitrix\Location\Repository\Location\IRepository
;
7
use
Bitrix\Location\Source\Osm\Api\Api
;
8
use
Bitrix\Main\ModuleManager
;
9
use
Bitrix\Main\Context
;
10
16
final
class
OsmSource
extends
Source
17
{
18
public
const
API_PATH
=
'/api'
;
19
21
private
$tokenRequester;
22
26
public
function
__construct
()
27
{
28
$this->tokenRequester = (
new
TokenRequester
())->setSource($this);
29
}
30
34
public
function
makeRepository
():
IRepository
35
{
36
static
$result =
null
;
37
38
if
($result !==
null
)
39
{
40
return
$result;
41
}
42
43
$result =
new
Repository
(
44
new
Api
($this),
45
$this
46
);
47
48
return
$result;
49
}
50
54
public
function
getJSParams
(): array
55
{
56
$token = $this->
getOsmToken
();
57
58
return
[
59
'serviceUrl'
=> $this->
getOsmApiUrl
(),
60
'mapServiceUrl'
=> $this->
getOsmMapServiceUrl
(),
61
'token'
=> $token ? $token->getToken() :
null
,
62
'useGeocodingService'
=>
true
,
63
'hostName'
=> $this->
getOsmHostName
()
64
];
65
}
66
70
public
function
convertLang
(
string
$bitrixLang): string
71
{
72
$langMap = [
73
'br'
=>
'pt'
,
// Portuguese (Brazil)
74
'la'
=>
'es'
,
// Spanish
75
'sc'
=>
'zh'
,
// Chinese (Simplified)
76
'tc'
=>
'zh'
,
// Chinese (Traditional)
77
'vn'
=>
'vi'
,
// Vietnamese
78
'ua'
=>
'uk'
,
// Ukrainian
79
];
80
81
return
$langMap[$bitrixLang] ?? $bitrixLang;
82
}
83
87
public
function
getOsmHostName
(): string
88
{
89
if
(defined(
'BX24_HOST_NAME'
) && ModuleManager::isModuleInstalled(
'bitrix24'
))
90
{
91
$result = BX24_HOST_NAME;
92
}
93
else
94
{
95
$result =
Context::getCurrent
()->getServer()->get(
'HTTP_HOST'
);
96
97
if
(strpos($result,
':'
) !==
false
)
98
{
99
$result = explode(
':'
, $result)[0];
100
}
101
}
102
103
return
$result;
104
}
105
109
public
function
getOsmApiUrl
(): ?string
110
{
111
$serviceUrl = $this->
getOsmServiceUrl
();
112
if
(!$serviceUrl)
113
{
114
return
null
;
115
}
116
117
return
$serviceUrl . static::API_PATH;
118
}
119
123
public
function
getOsmServiceUrl
(): ?string
124
{
125
if
(defined(
'LOCATION_OSM_SERVICE_URL'
) && LOCATION_OSM_SERVICE_URL)
126
{
127
return
(
string
)LOCATION_OSM_SERVICE_URL;
128
}
129
130
return
$this->
getConfig
()
131
? $this->
getConfig
()->getValue(
'SERVICE_URL'
)
132
:
null
;
133
}
134
138
public
function
getOsmMapServiceUrl
(): ?string
139
{
140
if
(defined(
'LOCATION_OSM_MAP_SERVICE_URL'
) && LOCATION_OSM_MAP_SERVICE_URL)
141
{
142
return
(
string
)LOCATION_OSM_MAP_SERVICE_URL;
143
}
144
145
return
$this->
getConfig
()
146
? $this->
getConfig
()->getValue(
'MAP_SERVICE_URL'
)
147
:
null
;
148
}
149
153
public
function
getOsmToken
(): ?
Token
154
{
155
return
$this->tokenRequester->
getToken
();
156
}
157
158
public
function
isAvailable
(): bool
159
{
160
$token = $this->tokenRequester->getToken();
161
if
($token)
162
{
163
return
true
;
164
}
165
166
return
!$this->tokenRequester->hasLicenseIssues();
167
}
168
}
Bitrix\Location\Entity\Source
Definition
source.php:17
Bitrix\Location\Entity\Source\getConfig
getConfig()
Definition
source.php:87
Bitrix\Location\Source\Osm\Api\Api
Definition
api.php:19
Bitrix\Location\Source\Osm\OsmSource
Definition
osmsource.php:17
Bitrix\Location\Source\Osm\OsmSource\__construct
__construct()
Definition
osmsource.php:26
Bitrix\Location\Source\Osm\OsmSource\getOsmApiUrl
getOsmApiUrl()
Definition
osmsource.php:109
Bitrix\Location\Source\Osm\OsmSource\getOsmToken
getOsmToken()
Definition
osmsource.php:153
Bitrix\Location\Source\Osm\OsmSource\getOsmServiceUrl
getOsmServiceUrl()
Definition
osmsource.php:123
Bitrix\Location\Source\Osm\OsmSource\convertLang
convertLang(string $bitrixLang)
Definition
osmsource.php:70
Bitrix\Location\Source\Osm\OsmSource\makeRepository
makeRepository()
Definition
osmsource.php:34
Bitrix\Location\Source\Osm\OsmSource\API_PATH
const API_PATH
Definition
osmsource.php:18
Bitrix\Location\Source\Osm\OsmSource\getOsmHostName
getOsmHostName()
Definition
osmsource.php:87
Bitrix\Location\Source\Osm\OsmSource\getOsmMapServiceUrl
getOsmMapServiceUrl()
Definition
osmsource.php:138
Bitrix\Location\Source\Osm\OsmSource\getJSParams
getJSParams()
Definition
osmsource.php:54
Bitrix\Location\Source\Osm\OsmSource\isAvailable
isAvailable()
Definition
osmsource.php:158
Bitrix\Location\Source\Osm\Repository
Definition
repository.php:23
Bitrix\Location\Source\Osm\Token
Definition
token.php:11
Bitrix\Location\Source\Osm\Token\getToken
getToken()
Definition
token.php:32
Bitrix\Location\Source\Osm\TokenRequester
Definition
tokenrequester.php:16
Bitrix\Main\Context\getCurrent
static getCurrent()
Definition
context.php:241
Bitrix\Main\ModuleManager
Definition
modulemanager.php:5
Bitrix\Location\Repository\Location\IRepository
Definition
irepository.php:11
Bitrix\Location\Entity\Source
Definition
config.php:3
Bitrix\Location\Source\Osm
Bitrix\Main\Context
Definition
culture.php:9
modules
location
lib
source
osm
osmsource.php
Создано системой
1.10.0