@@ -29,16 +29,16 @@ discard block |
||
| 29 | 29 | // Does doc has a array that does not exist in model definition . |
| 30 | 30 | if (!isset($my_model[$key])) { |
| 31 | 31 | if ($my_key !== null) { |
| 32 | - $my_key = strval($my_key) . " . " . strval($key); |
|
| 32 | + $my_key = strval($my_key)." . ".strval($key); |
|
| 33 | 33 | } else { |
| 34 | 34 | $my_key = $key; |
| 35 | 35 | } |
| 36 | - throw new \Exception("Error for key '" . $my_key . "' that does not exist in the model"); |
|
| 36 | + throw new \Exception("Error for key '".$my_key."' that does not exist in the model"); |
|
| 37 | 37 | } |
| 38 | 38 | // Is the value of the array[key] again another array? . |
| 39 | 39 | elseif (ModelUtils::gettype($my_doc[$key]) == "array") { |
| 40 | 40 | if ($my_key !== null) { |
| 41 | - $my_key = strval($my_key) . " . " . strval($key); |
|
| 41 | + $my_key = strval($my_key)." . ".strval($key); |
|
| 42 | 42 | } else { |
| 43 | 43 | $my_key = $key; |
| 44 | 44 | } |
@@ -51,16 +51,16 @@ discard block |
||
| 51 | 51 | // Does the value of the array[key] have same variable type that stated in the definition of the model array . |
| 52 | 52 | elseif (ModelUtils::gettype($my_doc[$key]) != $my_model[$key]['_type']) { |
| 53 | 53 | if ($my_key !== null) { |
| 54 | - $my_key = $my_key . " . " . $key; |
|
| 54 | + $my_key = $my_key." . ".$key; |
|
| 55 | 55 | } else { |
| 56 | 56 | $my_key = $key; |
| 57 | 57 | } |
| 58 | - throw new \Exception("Error for key '" . $my_key . "'" . ", " . ModelUtils::gettype($my_doc[$key]) . |
|
| 59 | - " given but it must be " . $my_model[$key]['_type']); |
|
| 58 | + throw new \Exception("Error for key '".$my_key."'".", ".ModelUtils::gettype($my_doc[$key]). |
|
| 59 | + " given but it must be ".$my_model[$key]['_type']); |
|
| 60 | 60 | } else { |
| 61 | 61 | $v_key = $key; |
| 62 | 62 | if ($my_key !== null) { |
| 63 | - $v_key = $my_key . " . " . $key; |
|
| 63 | + $v_key = $my_key." . ".$key; |
|
| 64 | 64 | } |
| 65 | 65 | $my_doc[$key] = ModelUtils::validate_doc_item($my_doc[$key], $my_model[$key], $v_key); |
| 66 | 66 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | $my_keys = array_keys($my_doc); |
| 81 | 81 | foreach ($my_keys as $key) { |
| 82 | 82 | // If array has a key that is not presented in the model definition, unset it . |
| 83 | - if (! isset($my_model[$key])) { |
|
| 83 | + if (!isset($my_model[$key])) { |
|
| 84 | 84 | unset($my_doc[$key]); |
| 85 | 85 | } |
| 86 | 86 | // If array[$key] is again an array, recursively fit this array too . |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | return $my_doc[$key]; |
| 92 | 92 | } |
| 93 | 93 | } elseif (ModelUtils::gettype($my_doc[$key]) == "array" && $my_model[$key]['_type'] != "array") { |
| 94 | - $my_doc[$key]=$my_model[$key]['_default']; |
|
| 94 | + $my_doc[$key] = $my_model[$key]['_default']; |
|
| 95 | 95 | } |
| 96 | 96 | // If array[key] is not an array and not has same variable type that stated in the model definition . |
| 97 | 97 | else { |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | public static function setting_model_defaults($my_model, $my_doc) |
| 112 | 112 | { |
| 113 | 113 | $my_keys = array_keys($my_model); |
| 114 | - $new_doc =[ ]; |
|
| 114 | + $new_doc = []; |
|
| 115 | 115 | foreach ($my_keys as $key) { |
| 116 | 116 | $item_keys = array_keys($my_model[$key]); |
| 117 | 117 | // If one of the keys of $my_model[$key] is _type this is a definition, not a defined key |
@@ -198,35 +198,35 @@ discard block |
||
| 198 | 198 | case 'mail': |
| 199 | 199 | $filter_check = filter_var($value, FILTER_VALIDATE_EMAIL); |
| 200 | 200 | if ($filter_check === false) { |
| 201 | - throw new \Exception("Error for value '" . $value . "' for '" . $key . "' couldn't pass the " . |
|
| 201 | + throw new \Exception("Error for value '".$value."' for '".$key."' couldn't pass the ". |
|
| 202 | 202 | "validation: INVALID_EMAIL_ADDRESS "); |
| 203 | 203 | } |
| 204 | 204 | break; |
| 205 | 205 | case 'bool': |
| 206 | 206 | $filter_check = filter_var($value, FILTER_VALIDATE_BOOLEAN); |
| 207 | 207 | if ($filter_check === false) { |
| 208 | - throw new \Exception("Error for value '" . $value . "' for '" . $key . "' couldn't pass the " . |
|
| 208 | + throw new \Exception("Error for value '".$value."' for '".$key."' couldn't pass the ". |
|
| 209 | 209 | "validation: INVALID_BOOLEAN_VALUE "); |
| 210 | 210 | } |
| 211 | 211 | break; |
| 212 | 212 | case 'url': |
| 213 | 213 | $filter_check = filter_var($value, FILTER_VALIDATE_URL); |
| 214 | 214 | if ($filter_check === false) { |
| 215 | - throw new \Exception("Error for value '" . $value . "' for '" . $key . "' couldn't pass the " . |
|
| 215 | + throw new \Exception("Error for value '".$value."' for '".$key."' couldn't pass the ". |
|
| 216 | 216 | "validation: INVALID_URL "); |
| 217 | 217 | } |
| 218 | 218 | break; |
| 219 | 219 | case 'ip': |
| 220 | 220 | $filter_check = filter_var($value, FILTER_VALIDATE_IP); |
| 221 | 221 | if ($filter_check === false) { |
| 222 | - throw new \Exception("Error for value '" . $value . "' for '" . $key . "' couldn't pass the " . |
|
| 222 | + throw new \Exception("Error for value '".$value."' for '".$key."' couldn't pass the ". |
|
| 223 | 223 | "validation: INVALID_IP_ADDRESS "); |
| 224 | 224 | } |
| 225 | 225 | break; |
| 226 | 226 | case 'mac_address': |
| 227 | 227 | $filter_check = filter_var($value, FILTER_VALIDATE_MAC); |
| 228 | 228 | if ($filter_check === false) { |
| 229 | - throw new \Exception("Error for value '" . $value . "' for '" . $key . "' couldn't pass the " . |
|
| 229 | + throw new \Exception("Error for value '".$value."' for '".$key."' couldn't pass the ". |
|
| 230 | 230 | "validation: INVALID_MAC_ADDRESS "); |
| 231 | 231 | } |
| 232 | 232 | break; |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | $regex = "/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/"; |
| 235 | 235 | $filter_check = filter_var($value, FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=> $regex))); |
| 236 | 236 | if ($filter_check === false) { |
| 237 | - throw new \Exception("Error for value '" . $value . "' for '" . $key . "' couldn't pass the " . |
|
| 237 | + throw new \Exception("Error for value '".$value."' for '".$key."' couldn't pass the ". |
|
| 238 | 238 | "validation: INVALID_FORMAT "); |
| 239 | 239 | } |
| 240 | 240 | break; |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | $regex = "/^([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])$/"; |
| 243 | 243 | $filter_check = filter_var($value, FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=> $regex))); |
| 244 | 244 | if ($filter_check === false) { |
| 245 | - throw new \Exception("Error for value '" . $value . "' for '" . $key . "' couldn't pass the " . |
|
| 245 | + throw new \Exception("Error for value '".$value."' for '".$key."' couldn't pass the ". |
|
| 246 | 246 | "validation: INVALID_FORMAT "); |
| 247 | 247 | } |
| 248 | 248 | break; |
@@ -250,14 +250,14 @@ discard block |
||
| 250 | 250 | $regex = "/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) ([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])$/"; |
| 251 | 251 | $filter_check = filter_var($value, FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=> $regex))); |
| 252 | 252 | if ($filter_check === false) { |
| 253 | - throw new \Exception("Error for value '" . $value . "' for '" . $key . "' couldn't pass the validation: INVALID_FORMAT "); |
|
| 253 | + throw new \Exception("Error for value '".$value."' for '".$key."' couldn't pass the validation: INVALID_FORMAT "); |
|
| 254 | 254 | } |
| 255 | 255 | break; |
| 256 | 256 | case 'regex': |
| 257 | 257 | $regex = "/^".$format."$/"; |
| 258 | 258 | $filter_check = filter_var($value, FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=> $regex))); |
| 259 | 259 | if ($filter_check === false) { |
| 260 | - throw new \Exception("Error for value '" . $value . "' for '" . $key . "' couldn't pass the " . |
|
| 260 | + throw new \Exception("Error for value '".$value."' for '".$key."' couldn't pass the ". |
|
| 261 | 261 | "validation: INVALID_FORMAT "); |
| 262 | 262 | } |
| 263 | 263 | break; |
@@ -267,37 +267,37 @@ discard block |
||
| 267 | 267 | case 'integer': |
| 268 | 268 | case 'float': |
| 269 | 269 | if ($min_length !== null) { |
| 270 | - if ($value < $min_length) { |
|
| 271 | - throw new \Exception("Error for value '" . $value . "' for '" . $key . "' couldn't pass the " . |
|
| 272 | - "validation: Must be bigger than " . $min_length . " "); |
|
| 270 | + if ($value<$min_length) { |
|
| 271 | + throw new \Exception("Error for value '".$value."' for '".$key."' couldn't pass the ". |
|
| 272 | + "validation: Must be bigger than ".$min_length." "); |
|
| 273 | 273 | } |
| 274 | 274 | } |
| 275 | 275 | if ($max_length !== null) { |
| 276 | 276 | if ($value>$max_length) { |
| 277 | - throw new \Exception("Error for value '" . $value . "' for '" . $key . "' couldn't pass the " . |
|
| 278 | - "validation: Must be smallerr than " . $max_length . " "); |
|
| 277 | + throw new \Exception("Error for value '".$value."' for '".$key."' couldn't pass the ". |
|
| 278 | + "validation: Must be smallerr than ".$max_length." "); |
|
| 279 | 279 | } |
| 280 | 280 | } |
| 281 | 281 | break; |
| 282 | 282 | default: |
| 283 | 283 | if ($max_length !== null) { |
| 284 | 284 | if (strlen($value)>$max_length) { |
| 285 | - throw new \Exception("Error for value '" . $value . "' for '" . $key . "' couldn't pass the " . |
|
| 286 | - "validation: It's length must be smaller than " . $max_length . " "); |
|
| 285 | + throw new \Exception("Error for value '".$value."' for '".$key."' couldn't pass the ". |
|
| 286 | + "validation: It's length must be smaller than ".$max_length." "); |
|
| 287 | 287 | } |
| 288 | 288 | } |
| 289 | 289 | if ($min_length !== null) { |
| 290 | 290 | if (strlen($value)<$min_length) { |
| 291 | - throw new \Exception("Error for value '" . $value . "' for '" . $key . "' couldn't pass the " . |
|
| 292 | - "validation: It's length must be longer than " . $min_length . " "); |
|
| 291 | + throw new \Exception("Error for value '".$value."' for '".$key."' couldn't pass the ". |
|
| 292 | + "validation: It's length must be longer than ".$min_length." "); |
|
| 293 | 293 | } |
| 294 | 294 | } |
| 295 | 295 | break; |
| 296 | 296 | } |
| 297 | 297 | if ($in_options !== null) { |
| 298 | 298 | if (!in_array($value, $in_options)) { |
| 299 | - throw new \Exception("Error for value '" . $value . "' for '" . $key . "' couldn't pass the validation: " . |
|
| 300 | - "It's length must be one of the these values: " . implode(", ", $in_options) . " "); |
|
| 299 | + throw new \Exception("Error for value '".$value."' for '".$key."' couldn't pass the validation: ". |
|
| 300 | + "It's length must be one of the these values: ".implode(", ", $in_options)." "); |
|
| 301 | 301 | } |
| 302 | 302 | } |
| 303 | 303 | |