mirror of
https://codeberg.org/reflect/reflect-rules-plugin.git
synced 2025-09-13 16:33:42 +02:00
feat: add method to validate and return Reflect\Response
if Ruleset
is invalid to the Ruleset
class (#16)
Closes #13 Reviewed-on: https://codeberg.org/reflect/reflect-rules-plugin/pulls/16 Co-authored-by: vlw <victor@vlw.se> Co-committed-by: vlw <victor@vlw.se>
This commit is contained in:
parent
4133b25e93
commit
df150f0d86
2 changed files with 9 additions and 0 deletions
|
@ -71,6 +71,8 @@ Ruleset->get_errors();
|
|||
|
||||
Use `Ruleset->is_valid(): bool` to quickly check if any errors are set.
|
||||
|
||||
You can also use `Ruleset->validate_or_exit(): true|Response` to automatically return a `Reflect\Response` with all errors to current STDOUT if validation fails.
|
||||
|
||||
# Installation
|
||||
|
||||
Install with composer
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
use \ReflectRules\Rules;
|
||||
|
||||
use \Reflect\Response;
|
||||
|
||||
require_once "Rules.php";
|
||||
|
||||
// Available superglobal scopes
|
||||
|
@ -169,4 +171,9 @@
|
|||
|
||||
return $this->is_valid;
|
||||
}
|
||||
|
||||
// Return Reflect\Response with errors and code 422 Unprocessable Content if validation failed
|
||||
public function validate_or_exit(): true|Response {
|
||||
return $this->is_valid() ? true : new Response($this->errors, 422);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue