From 6dc0447320272aaae51a98eb6606597019f986d3 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Wed, 20 Aug 2025 14:58:10 +0200 Subject: login produces devices and tokens --- src/Support/RequestValidator.php | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/Support/RequestValidator.php (limited to 'src/Support') diff --git a/src/Support/RequestValidator.php b/src/Support/RequestValidator.php new file mode 100644 index 0000000..40ede8b --- /dev/null +++ b/src/Support/RequestValidator.php @@ -0,0 +1,67 @@ +requestBody = json_decode($request->getContent(), true); + self::validateJson(); + + $this->requestQuery = $request->query->all(); + } + + /** + * types are validated with gettype + * @see gettype + * + * @param array $schemaRequired + * @param array $schemaOptional + */ + public function validateBody(array $schemaRequired, array $schemaOptional = []): void + { + throw new AppException( + ErrorCode::BAD_JSON, + "Request body is missing required values", + Response::HTTP_UNPROCESSABLE_ENTITY, + ); + } + + /** + * types are validated with gettype + * @see gettype + * + * @param array $schemaRequired + * @param array $schemaOptional + */ + public function validateQuery(array $schemaRequired, array $schemaOptional = []): void + { + throw new AppException( + ErrorCode::BAD_JSON, + "Request query is missing required values", + Response::HTTP_UNPROCESSABLE_ENTITY, + ); + } + + private function traverseRecursive(): void {} + + public static function validateJson(): void + { + if (json_last_error() !== JSON_ERROR_NONE) { + throw new AppException( + ErrorCode::NOT_JSON, + "Request did not contain valid JSON", + Response::HTTP_BAD_REQUEST, + ); + } + } +} -- cgit v1.2.3