1
1
<?php
2
2
/**
3
- * Contains the ValidationException based classes .
3
+ * Contains the Validate\Exception\ValueException class .
4
4
*
5
5
* @author Craig Manley
6
- * @copyright Copyright © 2016 , Craig Manley (www.craigmanley.com)
6
+ * @copyright Copyright © 2018 , Craig Manley (www.craigmanley.com)
7
7
* @license http://www.opensource.org/licenses/mit-license.php Licensed under MIT
8
8
*/
9
- namespace Validate ;
9
+ namespace Validate \ Exception ;
10
10
11
11
12
12
/**
13
- * ValidationException class
14
- *
15
- * @package Validate
13
+ * @ignore Require dependencies.
16
14
*/
17
- class ValidationException extends \Exception {}
18
-
19
-
15
+ require_once (__DIR__ . '/ValidationException.php ' );
20
16
21
17
22
18
/**
23
- * ValidationCheckException class.
19
+ * ValueException class. Encapsulates the check name, value, and message of the failed validation .
24
20
*/
25
- class ValidationCheckException extends ValidationException {
21
+ class ValueException extends ValidationException {
26
22
protected $ check ;
27
23
protected $ value ;
28
24
25
+
29
26
/**
30
27
* Constructor.
31
28
*
@@ -38,14 +35,15 @@ public function __construct($check, $value, $message = null) {
38
35
$ this ->check = $ check ;
39
36
$ this ->value = $ value ;
40
37
if (is_null ($ message )) {
41
- $ message = 'Failed validation check " ' . $ check . '" for ' . gettype ($ this ->value ) . ' value ' ;
38
+ $ message = 'Failed validation " ' . $ check . '" for ' . gettype ($ this ->value ) . ' value ' ;
42
39
if (is_scalar ($ value )) {
43
40
$ message .= ' ' . $ this ->getStringPlaceholderValue ();
44
41
}
45
42
}
46
43
parent ::__construct ($ message );
47
44
}
48
45
46
+
49
47
/**
50
48
* Return the name of the check that failed.
51
49
*
@@ -55,6 +53,7 @@ public function getCheck() {
55
53
return $ this ->check ;
56
54
}
57
55
56
+
58
57
/**
59
58
* Return a string representation of the scalar value that caused the failure, for use in error messages.
60
59
* If the value was not a scalar, then null is returned.
@@ -76,6 +75,7 @@ public function getStringPlaceholderValue() {
76
75
return null ;
77
76
}
78
77
78
+
79
79
/**
80
80
* Return the value that caused the failure.
81
81
*
@@ -85,6 +85,7 @@ public function getValue() {
85
85
return $ this ->value ;
86
86
}
87
87
88
+
88
89
/**
89
90
* Return a simplified string representation of the value that caused the failure.
90
91
*
@@ -100,48 +101,3 @@ public function getValueSimple() {
100
101
return gettype ($ this ->value );
101
102
}
102
103
}
103
-
104
-
105
-
106
-
107
-
108
- /**
109
- * ValidationNamedCheckException class.
110
- *
111
- * @package cmanley
112
- */
113
- class ValidationNamedCheckException extends ValidationCheckException {
114
- protected $ name ;
115
-
116
- /**
117
- * Constructor.
118
- *
119
- * @param string $name the parameter/key name
120
- * @param string $check name of check that failed
121
- * @param mixed $value the value that isn't valid
122
- * @param string $message optional custom message
123
- * @param array $options
124
- */
125
- public function __construct ($ name , $ check , $ value , $ message = null ) {
126
- $ this ->name = $ name ;
127
- $ this ->check = $ check ;
128
- $ this ->value = $ value ;
129
- if (is_null ($ message )) {
130
- $ message = 'Parameter " ' . $ name . '" failed validation check " ' . $ check . '" for ' . gettype ($ this ->value ) . ' value ' ;
131
- if (is_scalar ($ value )) {
132
- $ message .= ' ' . $ this ->getStringPlaceholderValue ();
133
- }
134
- }
135
- parent ::__construct ($ check , $ value , $ message );
136
- }
137
-
138
-
139
- /**
140
- * Return the name of the key, if known, that caused the failure.
141
- *
142
- * @return string|null
143
- */
144
- public function getName () {
145
- return $ this ->name ;
146
- }
147
- }
0 commit comments