| 1 | <?php |
||
| 12 | class Validate |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * Checks if value is true, if not throws ValidateException with the given message. |
||
| 16 | * |
||
| 17 | * @param bool $value |
||
| 18 | * @param string $message |
||
| 19 | * @return bool |
||
| 20 | * @throws ValidateException |
||
| 21 | */ |
||
| 22 | public static function isTrue($value, $message = '') |
||
| 23 | { |
||
| 24 | if ($value !== true) { |
||
| 25 | throw new ValidateException($message); |
||
| 26 | } |
||
| 27 | return true; |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Checks if value is a correct email address, otherwise throws ValidateException with the user given message. |
||
| 32 | * |
||
| 33 | * @param string $value |
||
| 34 | * @param string $message |
||
| 35 | * @return bool |
||
| 36 | * @throws ValidateException |
||
| 37 | */ |
||
| 38 | public static function isEmail($value, $message = '') |
||
| 39 | { |
||
| 40 | if (!filter_var($value, FILTER_VALIDATE_EMAIL)) { |
||
| 41 | throw new ValidateException($message); |
||
| 42 | } |
||
| 43 | return true; |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Checks if value is not null, otherwise throws ValidateException with the user given message. |
||
| 48 | * |
||
| 49 | * @param mixed $value |
||
| 50 | * @param string $message |
||
| 51 | * @return bool |
||
| 52 | * @throws ValidateException |
||
| 53 | */ |
||
| 54 | public static function isNotNull($value, $message = '') |
||
| 55 | { |
||
| 56 | if ($value === null) { |
||
| 57 | throw new ValidateException($message); |
||
| 58 | } |
||
| 59 | return true; |
||
| 60 | } |
||
| 61 | } |
||
| 62 |