forked from matomo-org/plugin-DeviceDetectorCache
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathConfiguration.php
More file actions
68 lines (54 loc) · 1.66 KB
/
Configuration.php
File metadata and controls
68 lines (54 loc) · 1.66 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
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\DynamicDeviceDetectorCache;
use Piwik\Config;
class Configuration
{
const KEY_CacheTTLInSeconds = 'cache_ttl_in_seconds';
const DEFAULT_CacheTTLInSeconds = 300;
public function install()
{
$config = $this->getConfig();
if (empty($config->DynamicDeviceDetectorCache)) {
$config->DynamicDeviceDetectorCache = [];
}
$cache = $config->DynamicDeviceDetectorCache;
// we make sure to set a value only if none has been configured yet, eg in common config.
if (empty($cache[self::KEY_CacheTTLInSeconds])) {
$cache[self::KEY_CacheTTLInSeconds] = self::DEFAULT_CacheTTLInSeconds;
}
$config->DynamicDeviceDetectorCache = $cache;
$config->forceSave();
}
public function uninstall()
{
$config = $this->getConfig();
$config->DynamicDeviceDetectorCache = [];
$config->forceSave();
}
/**
* @return int
*/
public function getCacheTTLInSeconds()
{
return $this->getConfigValue(self::KEY_CacheTTLInSeconds, self::DEFAULT_CacheTTLInSeconds);
}
private function getConfig()
{
return Config::getInstance();
}
private function getConfigValue($name, $default)
{
$config = $this->getConfig();
$attribution = $config->DynamicDeviceDetectorCache;
if (isset($attribution[$name])) {
return $attribution[$name];
}
return $default;
}
}