From aa7d969350f50d00d7dce01b948276946fcc0e81 Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Thu, 28 Nov 2024 17:05:16 +0000 Subject: [PATCH] feat: add return `Ruleset` instance to `Ruleset->GET()` and `Ruleset->POST()` (#17) Quick PR that adds return values to `Ruleset->GET()` and `Ruleset->POST()` to allow for method chaining with for example `Ruleset->validate_or_exit()`. This can come handy for streamlining simple rulesets. # Example ```php $ruleset->GET(new Rules("something")->type(Type::STRING))->validate_or_exit(); ``` Reviewed-on: https://codeberg.org/reflect/reflect-rules-plugin/pulls/17 --- src/Ruleset.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Ruleset.php b/src/Ruleset.php index ec5ffa7..0cc7e41 100644 --- a/src/Ruleset.php +++ b/src/Ruleset.php @@ -122,7 +122,7 @@ // ---- // Perform request processing on GET properties (search parameters) - public function GET(array $rules): void { + public function GET(array $rules): self { // (Re)enable strict mode if property is null if ($this->strict === null) { $this->strict = true; @@ -133,10 +133,12 @@ $this->eval_rules($rule, Scope::GET); } + + return $this; } // Perform request processing on POST properties (request body) - public function POST(array $rules): void { + public function POST(array $rules): self { // (Re)enable strict mode if property is null if ($this->strict === null) { $this->strict = true; @@ -147,6 +149,8 @@ $this->eval_rules($rule, Scope::POST); } + + return $this; } // ----