1 | <?php |
||
35 | class Assert { |
||
36 | |||
37 | /** @var boolean */ |
||
38 | public static $throwExceptions = true; |
||
39 | |||
40 | /** |
||
41 | * Check if the argument is a string and not empty, accepts empty strings. |
||
42 | * @param string $argument the arguments to validate |
||
43 | * @throws \InvalidArgumentException if the validation fails |
||
44 | * @return boolean check result |
||
45 | */ |
||
46 | 2 | public static function isString($argument) { |
|
51 | |||
52 | /** |
||
53 | * Check if the argument is an integer. |
||
54 | * @param integer $argument the argument to check |
||
55 | * @throws \InvalidArgumentException if the validation fails |
||
56 | * @return boolean check result |
||
57 | */ |
||
58 | 2 | public static function isInteger($argument) { |
|
63 | |||
64 | /** |
||
65 | * Check if the argument is a string or a integer, accepts empty values. |
||
66 | * @param string $argument the argument to validate |
||
67 | * @throws \InvalidArgumentException if the validation fails |
||
68 | * @return boolean check result |
||
69 | */ |
||
70 | 2 | public static function isStringOrInteger($argument) { |
|
76 | |||
77 | /** |
||
78 | * Check if the arguments is a float. |
||
79 | * @param float $argument the argument to check |
||
80 | * @throws \InvalidArgumentException if the validation fails |
||
81 | * @return boolean check result |
||
82 | */ |
||
83 | 2 | public static function isFloat($argument) { |
|
88 | |||
89 | /** |
||
90 | * Check if the argument is a boolean. |
||
91 | * @param boolean $argument the argument to validate |
||
92 | * @throws \InvalidArgumentException if the validation fails |
||
93 | * @return boolean check result |
||
94 | */ |
||
95 | 2 | public static function isBoolean($argument) { |
|
100 | |||
101 | /** |
||
102 | * Check if the argument is not empty. |
||
103 | * @param mixed $argument the argument to validate |
||
104 | * @throws \InvalidArgumentException if the validation fails |
||
105 | * @return boolean check result |
||
106 | */ |
||
107 | 2 | public static function isNotEmpty($argument) { |
|
112 | |||
113 | /** |
||
114 | * Check if a function is available by its name. |
||
115 | * @param string $argument the argument to validate |
||
116 | * @throws \InvalidArgumentException if the validation fails |
||
117 | * @return boolean check result |
||
118 | */ |
||
119 | 2 | public static function isFunctionAvailable($argument) { |
|
124 | |||
125 | /** |
||
126 | * Check if the argument is traversable. |
||
127 | * @param \Traversable|array $argument the argument to validate |
||
128 | * @throws \InvalidArgumentException if the validation fails |
||
129 | * @return boolean check result |
||
130 | */ |
||
131 | 2 | public static function isTraversable($argument) { |
|
137 | |||
138 | /** |
||
139 | * Check if the argument is callable. |
||
140 | * @param callable $argument the argument to validate |
||
141 | * @throws \InvalidArgumentException if the validation fails |
||
142 | * @return boolean check result |
||
143 | */ |
||
144 | 2 | public static function isCallable($argument) { |
|
149 | |||
150 | /** |
||
151 | * Check if the argument is an object. |
||
152 | * @param object $argument the argument to validate |
||
153 | * @throws \InvalidArgumentException if the validation fails |
||
154 | * @return boolean check result |
||
155 | */ |
||
156 | 2 | public static function isObject($argument) { |
|
161 | |||
162 | /** |
||
163 | * Check if the argument is a resource. |
||
164 | * @param resource $argument the argument to validate |
||
165 | * @throws \InvalidArgumentException if the validation fails |
||
166 | * @return boolean check result |
||
167 | */ |
||
168 | 2 | public static function isResource($argument) { |
|
173 | |||
174 | /** |
||
175 | * Handle an invalid argument. |
||
176 | * @param boolean $validationSuccess |
||
177 | * @param mixed $argument |
||
178 | * @param string $errorMessage |
||
179 | * @throws \InvalidArgumentException |
||
180 | * @return boolean false if exception is turned off |
||
181 | */ |
||
182 | 14 | public static function handleArgumentValidation($validationSuccess, $argument, $errorMessage) { |
|
193 | |||
194 | /** |
||
195 | * Throw an \InvalidArgumentException describing the argument and adding a helpful error message. |
||
196 | * @param mixed $argument the arguments which are invalid |
||
197 | * @param string $errorMessage the error message to attach |
||
198 | * @return \InvalidArgumentException |
||
199 | */ |
||
200 | 2 | public static function getInvalidArgumentException($argument, $errorMessage) { |
|
203 | |||
204 | /** |
||
205 | * Return the formatted error message. |
||
206 | * @param mixed $argument |
||
207 | * @param string $errorMessage |
||
208 | * @return string the error message |
||
209 | */ |
||
210 | 3 | private static function getErrorMessage($argument, $errorMessage) { |
|
217 | |||
218 | /** |
||
219 | * Return the argument string representation. |
||
220 | * @param mixed $argument the argument to return the representation |
||
221 | * @return string the argument representation |
||
222 | */ |
||
223 | 4 | private static function getArgumentStringRepresentation($argument) { |
|
237 | |||
238 | } |
||
239 |