Welcome to mirror list, hosted at ThFree Co, Russian Federation.

WhitelistedValue.php « Validators « core - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b1682e3014d60e36dcf6b698f0109f3bda2c556b (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
/**
 * 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\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))));
        }

    }
}