summaryrefslogtreecommitdiff
path: root/src/Support/RequestValidator.php
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2025-08-20 14:58:10 +0200
committerDaniel Weipert <git@mail.dweipert.de>2025-08-20 14:58:10 +0200
commit6dc0447320272aaae51a98eb6606597019f986d3 (patch)
tree0acb527801a1d9eac943b5e0b0ccb33e610cd755 /src/Support/RequestValidator.php
parentd08f4c83470c25d35d24594bd73e4effdac191a0 (diff)
login produces devices and tokens
Diffstat (limited to 'src/Support/RequestValidator.php')
-rw-r--r--src/Support/RequestValidator.php67
1 files changed, 67 insertions, 0 deletions
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 @@
+<?php
+
+namespace App\Support;
+
+use App\Errors\AppException;
+use App\Errors\ErrorCode;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+
+class RequestValidator
+{
+ private array $requestBody;
+ private array $requestQuery;
+
+ public function __construct(private Request $request)
+ {
+ $this->requestBody = json_decode($request->getContent(), true);
+ self::validateJson();
+
+ $this->requestQuery = $request->query->all();
+ }
+
+ /**
+ * types are validated with gettype
+ * @see gettype
+ *
+ * @param array<mixed,mixed> $schemaRequired
+ * @param array<mixed,mixed> $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<mixed,mixed> $schemaRequired
+ * @param array<mixed,mixed> $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,
+ );
+ }
+ }
+}