DLight\Application\Request

Mô tả: wrapper đọc dữ liệu request hiện tại: method/uri, query (GET), body (POST/JSON), headers, cookies và server vars.

Namespace / đăng ký

  • Namespace: DLight\Application
  • File: src/Application/Request.php

Public API

  • __construct()
  • getMethod(): string
  • getUri(): string
  • getQueryParams(): array
  • getBodyParams(): array
  • getHeaders(): array
  • getHeader(string $key, mixed $default = null): mixed
  • getCookies(): array
  • cookie(string $key, mixed $default = null): mixed
  • getServer(): array
  • input(string $key, mixed $default = null): mixed
  • all(): array

Cách dùng + demo

use DLight\Application\Request;

$req = new Request();

$method = $req->getMethod();
$uri    = $req->getUri();

$page   = $req->input('page', 1);          // ưu tiên body, fallback query
$token  = $req->getHeader('X-CSRF-TOKEN'); // header keys đã normalize lowercase

$data = $req->all();

Body sẽ được parse theo Content-Type: application/json → decode JSON, x-www-form-urlencoded / multipart/form-data$_POST, còn lại → lưu raw vào ['_raw'].