From 26c2557e221d1eefeee8473490940340cb56bd6d Mon Sep 17 00:00:00 2001 From: xl Date: Tue, 2 May 2023 15:28:28 +0800 Subject: [PATCH] modify value type --- src/Validator/Validator.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Validator/Validator.php b/src/Validator/Validator.php index 509669b..b1d850b 100644 --- a/src/Validator/Validator.php +++ b/src/Validator/Validator.php @@ -51,10 +51,10 @@ class Validator } - /** - * @param ServerRequestInterface|Request $request - * @return Validator - */ + /** + * @param ServerRequestInterface|Request $request + * @return Validator + */ public function bindData(ServerRequestInterface|Request $request): static { if ($request->isPost) { @@ -64,6 +64,12 @@ class Validator } foreach ($data as $key => $value) { if (property_exists($this->formData, $key)) { + $type = new \ReflectionProperty($this->formData, $key); + $value = match ($type->getType()->getName()) { + 'int' => (int)$value, + 'float' => (float)$value, + default => $value + }; $this->formData->{$key} = $value; } }