| @@ 179-200 (lines=22) @@ | ||
| 176 | * @param string $level |
|
| 177 | * @return Assert |
|
| 178 | */ |
|
| 179 | public static function that($value, string $fieldName='', int $code=0, string $error='', string $level=Assert::WARNING) : Assert |
|
| 180 | { |
|
| 181 | $assert = new static($value); |
|
| 182 | if ( $fieldName ) |
|
| 183 | { |
|
| 184 | $assert->fieldName($fieldName); |
|
| 185 | } |
|
| 186 | if ( $code ) |
|
| 187 | { |
|
| 188 | $assert->code($code); |
|
| 189 | } |
|
| 190 | if ( $error ) |
|
| 191 | { |
|
| 192 | $assert->error($error); |
|
| 193 | } |
|
| 194 | if ( $level ) |
|
| 195 | { |
|
| 196 | $assert->level($level); |
|
| 197 | } |
|
| 198 | ||
| 199 | return $assert; |
|
| 200 | } |
|
| 201 | ||
| 202 | /** |
|
| 203 | * @param mixed $value |
|
| @@ 34-55 (lines=22) @@ | ||
| 31 | * @param string $level |
|
| 32 | * @return Assert |
|
| 33 | */ |
|
| 34 | function Assert($value, string $fieldName='', int $code=0, string $error='', string $level=Assert::WARNING) |
|
| 35 | { |
|
| 36 | $assert = new Assert($value); |
|
| 37 | if ( $fieldName ) |
|
| 38 | { |
|
| 39 | $assert->fieldName($fieldName); |
|
| 40 | } |
|
| 41 | if ( $code ) |
|
| 42 | { |
|
| 43 | $assert->code($code); |
|
| 44 | } |
|
| 45 | if ( $error ) |
|
| 46 | { |
|
| 47 | $assert->error($error); |
|
| 48 | } |
|
| 49 | if ( $level ) |
|
| 50 | { |
|
| 51 | $assert->level($level); |
|
| 52 | } |
|
| 53 | ||
| 54 | return $assert; |
|
| 55 | } |
|
| 56 | ||
| 57 | /** |
|
| 58 | * Instantiate and return an Assert object, set to @throw ValidationFailedException. |
|
| @@ 67-88 (lines=22) @@ | ||
| 64 | * @param string $level |
|
| 65 | * @return Assert |
|
| 66 | */ |
|
| 67 | function Validate($value, string $fieldName='', int $code=0, string $error='', string $level=Assert::WARNING) |
|
| 68 | { |
|
| 69 | $assert = new Assert($value); |
|
| 70 | if ( $fieldName ) |
|
| 71 | { |
|
| 72 | $assert->fieldName($fieldName); |
|
| 73 | } |
|
| 74 | if ( $code ) |
|
| 75 | { |
|
| 76 | $assert->code($code); |
|
| 77 | } |
|
| 78 | if ( $error ) |
|
| 79 | { |
|
| 80 | $assert->error($error); |
|
| 81 | } |
|
| 82 | if ( $level ) |
|
| 83 | { |
|
| 84 | $assert->level($level); |
|
| 85 | } |
|
| 86 | ||
| 87 | return $assert->setExceptionClass(ValidationFailedException::class); |
|
| 88 | } |
|