From d6accce0691890c085fdfa2a0061e97ac3b02e20 Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Wed, 20 Nov 2024 11:31:52 +0100 Subject: [PATCH] feat: add validate or return Reflect\Response method to Ruleset --- src/Ruleset.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Ruleset.php b/src/Ruleset.php index dc7ff3e..ec5ffa7 100644 --- a/src/Ruleset.php +++ b/src/Ruleset.php @@ -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); + } } \ No newline at end of file