From 27a3b72ef824cae85a0f0f5a739391a132fd0924 Mon Sep 17 00:00:00 2001 From: unknown <13521043@std.stei.itb.ac.id> Date: Tue, 31 Oct 2023 09:41:54 +0700 Subject: [PATCH] Create ApiKeyHandler.php --- src/middleware/ApiKeyHandler.php | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/middleware/ApiKeyHandler.php diff --git a/src/middleware/ApiKeyHandler.php b/src/middleware/ApiKeyHandler.php new file mode 100644 index 0000000..7a683bd --- /dev/null +++ b/src/middleware/ApiKeyHandler.php @@ -0,0 +1,35 @@ +<?php + +class ApiKeyHandler +{ + private static $instance; + private $apiKey; + + private function __construct() + { + $this->apiKey = $_ENV['API_KEY']; + } + /** + * @return ApiKeyHandler + */ + public static function getInstance() + { + if (!isset(self::$instance)) { + self::$instance = new static(); + } + return self::$instance; + } + + public function checkApiKey($apiKeyHeader) + { + $res = $this->apiKey === $apiKeyHeader; + // if (!$res) { + // throw new Exception('Invalid API Key'); + // } + return $res; + } + +} + + +?> \ No newline at end of file -- GitLab