From e7014888f10b54c4e792191ff219c0f0b651af75 Mon Sep 17 00:00:00 2001 From: Yanik Kumar Date: Tue, 15 Jul 2025 15:07:53 +0530 Subject: [PATCH] Added file and hasFile method in request --- CHANGELOG.md | 2 +- core/Http/Request.php | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55f41d5..0144fd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ Earlier releases (`v0.1.0-alpha.1` to `v0.1.7-alpha.1`) were experimental and do --- -## [v0.1.7-alpha.2] - YYYY-MM-DD +## [v0.1.7-alpha.2] - 2025-07-15 ### Changed diff --git a/core/Http/Request.php b/core/Http/Request.php index 3524705..ed475ef 100644 --- a/core/Http/Request.php +++ b/core/Http/Request.php @@ -2,10 +2,12 @@ namespace Core\Http; -class Request { +class Request +{ public $method, $uri; - private function __construct($method, $uri) { + private function __construct($method, $uri) + { $this->method = $method; $this->uri = $uri; } @@ -13,10 +15,27 @@ private function __construct($method, $uri) { /** * Static method that reads the HTTP method + URI and returns a new Request object */ - public static function capture(){ + public static function capture() + { $method = $_SERVER['REQUEST_METHOD']; $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); return new self($method, $uri); } + + /** + * File method to get the input files + */ + public function file($key) + { + return $_FILES[$key] ?? null; + } + + /** + * File method to check if input is file + */ + public function hasFile($key) + { + return isset($_FILES[$key]) && is_uploaded_file($_FILES[$key]['tmp_name']); + } } \ No newline at end of file