data = array_merge($_GET, $_POST, $_REQUEST); } /** * Get all input data */ public function all(): array { return $this->data; } /** * Get input value by key */ public function input(string $key, $default = null) { return $this->data[$key] ?? $default; } /** * Get only specified keys */ public function only(array $keys): array { return array_intersect_key($this->data, array_flip($keys)); } /** * Get all except specified keys */ public function except(array $keys): array { return array_diff_key($this->data, array_flip($keys)); } /** * Check if key exists */ public function has(string $key): bool { return isset($this->data[$key]); } /** * Get request method */ public function method(): string { return $_SERVER['REQUEST_METHOD'] ?? 'GET'; } /** * Check if method is POST */ public function isPost(): bool { return $this->method() === 'POST'; } /** * Check if method is GET */ public function isGet(): bool { return $this->method() === 'GET'; } /** * Get request URI */ public function uri(): string { return $_SERVER['REQUEST_URI'] ?? '/'; } /** * Get request path */ public function path(): string { return parse_url($this->uri(), PHP_URL_PATH); } /** * Get query string */ public function query(): string { return $_SERVER['QUERY_STRING'] ?? ''; } /** * Get headers */ public function headers(): array { if (function_exists('getallheaders')) { $h = getallheaders(); return is_array($h) ? $h : []; } // Fallback build from $_SERVER $headers = []; foreach ($_SERVER as $key => $value) { if (strpos($key, 'HTTP_') === 0) { $name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($key, 5))))); $headers[$name] = $value; } elseif (in_array($key, ['CONTENT_TYPE', 'CONTENT_LENGTH'])) { $name = str_replace('_', '-', ucwords(strtolower($key), '_')); $headers[$name] = $value; } } return $headers; } /** * Get specific header */ public function header(string $name): ?string { $headers = $this->headers(); return $headers[$name] ?? null; } /** * Check if request is AJAX */ public function isAjax(): bool { return $this->header('X-Requested-With') === 'XMLHttpRequest'; } /** * Check if request expects JSON */ public function expectsJson(): bool { $accept = $this->header('Accept') ?? ''; return stripos($accept, 'application/json') !== false; } /** * Get file upload */ public function file(string $key): ?array { return $_FILES[$key] ?? null; } /** * Get all files */ public function files(): array { return $_FILES; } /** * Get IP address */ public function ip(): string { return $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['HTTP_X_REAL_IP'] ?? $_SERVER['REMOTE_ADDR'] ?? 'unknown'; } /** * Get user agent */ public function userAgent(): string { return $_SERVER['HTTP_USER_AGENT'] ?? ''; } /** * Get referer */ public function referer(): ?string { return $_SERVER['HTTP_REFERER'] ?? null; } }