-
-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathSettings.php
More file actions
165 lines (130 loc) · 4.29 KB
/
Settings.php
File metadata and controls
165 lines (130 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
/**
* SimpleMap for Craft CMS
*
* @link https://ethercreative.co.uk
* @copyright Copyright (c) 2019 Ether Creative
*/
namespace ether\simplemap\models;
use Craft;
use craft\base\Model;
use craft\helpers\App;
use craft\helpers\ConfigHelper;
use ether\simplemap\enums\GeoService;
use ether\simplemap\enums\MapTiles;
use ether\simplemap\services\GeoLocationService;
use ether\simplemap\SimpleMap;
use Exception;
/**
* Class Settings
*
* @author Ether Creative
* @package ether\simplemap\models
*/
class Settings extends Model
{
// Properties
// =========================================================================
/** @deprecated */
public $browserApiKey, $serverApiKey, $apiKey, $unrestrictedApiKey;
// Properties: Map
// -------------------------------------------------------------------------
/** @var string The map tile set to use */
public string $mapTiles = MapTiles::CartoVoyager;
/** @var string|array The token for the map tile set */
public string|array $mapToken = '';
// Properties: Geo-coding
// -------------------------------------------------------------------------
/** @var string The geo-coding service to use */
public string $geoService = GeoService::Nominatim;
/** @var string|array The token for the geo-coding service */
public string|array $geoToken = '';
/**
* @var bool Will disable the automatic population of missing field data.
* This can be useful in preventing API spam when importing lots of map
* data.
*/
public bool $disablePopulateMissingFieldData = false;
/**
* @var string The base URL for the Nominatim service. Override to use a
* self-hosted instance or a proxy.
*/
public string $nominatimBaseUrl = 'https://nominatim.openstreetmap.org';
// Properties: w3w
// -------------------------------------------------------------------------
/**
* @var bool Will enable what3words integration when set to true
*/
public bool $w3wEnabled = false;
/**
* @var string The token (API Key) for what3words
*/
public string $w3wToken = '';
// Properties: Geo-location
// -------------------------------------------------------------------------
/** @var string The geo-location service */
public string $geoLocationService = GeoLocationService::None;
/** @var string|array The token for the geo-location service */
public string|array $geoLocationToken = '';
/** @var string|int How long to cache IP look-ups for (set to 0 to disable caching) */
public string|int $geoLocationCacheDuration = 'P2M';
/** @var bool Will automatically redirect the user according to $geoLocationRedirectMap when true */
public bool $geoLocationAutoRedirect = false;
/**
* @var array A key value array where key is the handle of the site to
* redirect, and value is a key value array of user location properties
* and their required matches or an * string to catch all.
*
* @example [
* 'uk' => [ 'countryCode' => 'uk' ],
* 'eu' => [ 'isEU' => true ],
* 'global' => '*',
* ]
*/
public array $geoLocationRedirectMap = [];
// Methods
// =========================================================================
public function __construct ($config = [])
{
parent::__construct($config);
try {
$this->geoLocationCacheDuration = ConfigHelper::durationInSeconds(
$this->geoLocationCacheDuration
);
} catch (Exception $e) {
Craft::error($e->getMessage());
}
}
public function isW3WEnabled (): bool
{
return $this->w3wEnabled && SimpleMap::v(SimpleMap::EDITION_PRO);
}
// Getters
// =========================================================================
public function getMapToken (): bool|array|string|null
{
return $this->_parseEnv($this->mapToken);
}
public function getGeoToken (): bool|array|string|null
{
return $this->_parseEnv($this->geoToken);
}
public function getW3WToken (): bool|array|string|null
{
return $this->_parseEnv($this->w3wToken);
}
public function getGeoLocationToken (): bool|array|string|null
{
return $this->_parseEnv($this->geoLocationToken);
}
// Helpers
// =========================================================================
private function _parseEnv ($value): array|bool|string|null
{
if (is_string($value))
return App::parseEnv($value);
return array_map(function ($v) {
return App::parseEnv($v);
}, $value);
}
}