blob: 952bef3bad64429ab87c8a4ea557cce15d66d6fb (
plain)
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
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Validators;
use Piwik\Piwik;
class WhitelistedValue extends BaseValidator
{
private $whitelisted = array();
/**
* @param array $whitelistedValues
*/
public function __construct($whitelistedValues)
{
if (!is_array($whitelistedValues)) {
throw new Exception('The whitelisted values need to be an array');
}
$this->whitelisted = $whitelistedValues;
}
public function validate($value)
{
if (!in_array($value, $this->whitelisted, true)) {
throw new Exception(Piwik::translate('General_ValidatorErrorXNotWhitelisted', array($value, implode(', ', $this->whitelisted))));
}
}
}
|