diff options
Diffstat (limited to 'services/app/src/Form/FormState.php')
| -rw-r--r-- | services/app/src/Form/FormState.php | 62 |
1 files changed, 62 insertions, 0 deletions
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 @@ +<?php + +declare(strict_types=1); + +namespace Nsfisis\Albatross\Form; + +use Psr\Http\Message\ServerRequestInterface; + +final class FormState +{ + /** + * @var array<string, string> + */ + private array $errors = []; + + /** + * @param array<string, string> $params + */ + public function __construct(private readonly array $params = []) + { + } + + public static function fromRequest(ServerRequestInterface $request): self + { + return new self((array)$request->getParsedBody()); + } + + /** + * @return array<string, string> + */ + 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<string, string> $errors + */ + public function setErrors(array $errors): self + { + $this->errors = $errors; + return $this; + } + + /** + * @return array<string, string> + */ + public function getErrors(): array + { + return $this->errors; + } +} |
