-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathOneOfValidator.php
53 lines (45 loc) · 1001 Bytes
/
OneOfValidator.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
<?php declare(strict_types=1);
namespace MyENA\RGW\Validator;
use MyENA\RGW\Validator;
/**
* Class OneOfValidator
* @package MyENA\RGW\Validator
*/
class OneOfValidator implements Validator
{
public const NAME = 'one-of';
/** @var array */
private $allowed = [];
/**
* RequiredValidator constructor.
* @param array $allowed
*/
public function __construct(array $allowed)
{
$this->allowed = $allowed;
}
/**
* @return string
*/
public function name(): string
{
return self::NAME;
}
/**
* @param mixed $value
* @return bool
*/
public function test($value): bool
{
return in_array($value, $this->allowed, true);
}
/**
* @return string
*/
public function expectedStatement(): string
{
return 'value equating to one of: [' .
implode(', ', array_map('\\MyENA\\RGW\\stringifyValueTyped', $this->allowed)) .
']';
}
}