-
Notifications
You must be signed in to change notification settings - Fork 6
/
PluginSettings.php
80 lines (66 loc) · 1.82 KB
/
PluginSettings.php
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
<?php
/**
* Matomo - Open source web analytics
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @copyright (c) 2016 Joubert RedRat
* @author Joubert RedRat <[email protected]>
* @license MIT
* @category Matomo_Plugins
* @package ProtectTrackID
*/
declare(strict_types=1);
namespace Piwik\Plugins\ProtectTrackID;
use Piwik\Container\StaticContainer;
class PluginSettings
{
const BASE_REGEX = '/^[a-zA-Z0-9]+$/';
const SALT_MIN_LENGTH = 10;
const MIN_LENGTH = 5;
const MAX_LENGTH = 25;
public $base;
public $salt;
public $length;
public function __construct($base, $salt, $length)
{
$this->base = $base;
$this->salt = $salt;
$this->length = $length;
}
public function hasValidValues(): bool
{
if (is_null($this->base) || empty($this->base)) {
return false;
}
if (is_null($this->salt) || empty($this->salt)) {
return false;
}
if (is_null($this->length) || empty($this->length)) {
return false;
}
return true;
}
public static function isValidBase(string $base): bool
{
return (bool) preg_match(self::BASE_REGEX, $base);
}
public static function isValidSalt(string $salt): bool
{
return mb_strlen($salt) >= self::SALT_MIN_LENGTH;
}
public static function isValidLenght(int $length): bool
{
return $length >= self::MIN_LENGTH && $length <= self::MAX_LENGTH;
}
public static function createFromSettings(): self
{
$settings = StaticContainer::get(SystemSettings::class);
return new self(
$settings->base->getValue(),
$settings->salt->getValue(),
$settings->length->getValue(),
);
}
}