From deacd0dfc195bca41af631114804d29937337cd8 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Wed, 17 Jan 2024 02:11:31 +0900 Subject: . --- services/app/src/Form/FormState.php | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 services/app/src/Form/FormState.php (limited to 'services/app/src/Form/FormState.php') diff --git a/services/app/src/Form/FormState.php b/services/app/src/Form/FormState.php new file mode 100644 index 0000000..e56e8f0 --- /dev/null +++ b/services/app/src/Form/FormState.php @@ -0,0 +1,62 @@ + + */ + private array $errors = []; + + /** + * @param array $params + */ + public function __construct(private readonly array $params = []) + { + } + + public static function fromRequest(ServerRequestInterface $request): self + { + return new self((array)$request->getParsedBody()); + } + + /** + * @return array + */ + public function getParams(): array + { + return $this->params; + } + + public function get(string $key): ?string + { + $value = $this->params[$key] ?? null; + if (isset($value)) { + return $key === 'password' ? $value : trim($value); + } else { + return null; + } + } + + /** + * @param array $errors + */ + public function setErrors(array $errors): self + { + $this->errors = $errors; + return $this; + } + + /** + * @return array + */ + public function getErrors(): array + { + return $this->errors; + } +} -- cgit v1.2.3-70-g09d2