-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCustomValidator.php
59 lines (51 loc) · 1.15 KB
/
CustomValidator.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
<?php declare(strict_types=1);
namespace MyENA\RGW\Validator;
use MyENA\RGW\Validator;
/**
* Class CustomValidator
* @package MyENA\RGW\Validator
*/
class CustomValidator implements Validator
{
public const NAME = 'custom';
/** @var string */
private $name;
/** @var \Closure */
private $callable;
/** @var string */
private $expects;
/**
* CustomValidator constructor.
* @param string $name
* @param $callable
* @param string $expects
*/
public function __construct(string $name, $callable, string $expects = 'true from custom validator callable')
{
$this->name = $name;
$this->callable = $callable;
$this->expects = $expects;
}
/**
* @return string
*/
public function name(): string
{
return $this->name ?? self::NAME;
}
/**
* @param mixed $value
* @return bool
*/
public function test($value): bool
{
return (bool)call_user_func($this->callable, $value);
}
/**
* @return string
*/
public function expectedStatement(): string
{
return $this->expects;
}
}