1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of slick/validator package |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Slick\Validator; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* AbstractValidator |
14
|
|
|
* |
15
|
|
|
* @package Slick\Validator |
16
|
|
|
* @author Filipe Silva <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
abstract class AbstractValidator |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var mixed The value to evaluate |
23
|
|
|
*/ |
24
|
|
|
protected $value; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @readwrite |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
protected $message = ''; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var array Error messages templates |
34
|
|
|
*/ |
35
|
|
|
protected $messageTemplate = ''; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Returns an array of messages that explain why the most recent |
39
|
|
|
* isValid() call returned false. The array keys are validation failure |
40
|
|
|
* message identifiers, and the array values are the corresponding |
41
|
|
|
* human-readable message strings. |
42
|
|
|
* |
43
|
|
|
* @return array |
44
|
|
|
*/ |
45
|
22 |
|
public function getMessage() |
46
|
|
|
{ |
47
|
22 |
|
return $this->message; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Sets a custom message for a given identifier |
52
|
|
|
* |
53
|
|
|
* @param string $message |
54
|
|
|
* |
55
|
|
|
* @return AbstractValidator |
56
|
|
|
*/ |
57
|
4 |
|
public function setMessage($message) |
58
|
|
|
{ |
59
|
4 |
|
$this->messageTemplate = $message; |
|
|
|
|
60
|
4 |
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Adds a message using a template. |
65
|
|
|
* |
66
|
|
|
* @param string $template Message template. |
67
|
|
|
* |
68
|
|
|
* @return AbstractValidator |
69
|
|
|
*/ |
70
|
34 |
|
protected function addMessage($template) |
|
|
|
|
71
|
|
|
{ |
72
|
34 |
|
$arguments = func_get_args(); |
73
|
34 |
|
$template = $arguments[0]; |
74
|
|
|
|
75
|
34 |
|
$arguments[0] = $template; |
76
|
|
|
|
77
|
34 |
|
$this->message = sizeof($arguments) > 1 |
|
|
|
|
78
|
34 |
|
? call_user_func_array('sprintf', $arguments) |
79
|
34 |
|
: $this->message = $template; |
80
|
|
|
|
81
|
34 |
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..