Download the PHP package fastpress/request without Composer
On this page you can find all versions of the php package fastpress/request. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fastpress/request
More information about fastpress/request
Files in fastpress/request
Package request
Short Description A powerful and flexible HTTP request handling library for PHP, optimized for use with the Fastpress framework. Provides an easy-to-use interface for accessing request data and handling common request operations.
License MIT
Homepage https://github.com/fastpress/request
Informations about the package request
Fastpress HTTP Request
This repository contains the Request
class, a crucial component of the fastpress/framework
. The Request
class provides a comprehensive interface for handling HTTP requests in PHP applications. It simplifies accessing request data such as GET, POST, COOKIE, and SERVER variables, and includes methods for common request operations.
Features
- Easy retrieval of GET, POST, COOKIE, and SERVER data.
- Convenience methods for checking the HTTP request method (GET, POST, PUT, DELETE).
- Utilities for common tasks like checking for Ajax requests and secure connections.
- Flexibility to extend or modify for custom use-cases.
Installation
To use this component, first ensure you have fastpress/framework
installed. This Request
class is a dependency of the framework and is meant to be used within its context.
If you are managing your project with Composer, you can add this dependency directly by running:
Ensure that this aligns with the version constraints of fastpress/framework.
Usage
To use the Request class, create an instance of it in your PHP application:
Methods
validateCsrf(): bool
Validates the CSRF token.
-
Returns: true if the CSRF token is valid, otherwise throws a RuntimeException.
- Generates a new CSRF token and stores it in the session.
Returns: The generated CSRF token.
input(string $key, mixed $default = null, bool $sanitize = true): mixed
Retrieves an input value from GET, POST, or JSON data.
$key: The input key. $default: Optional. The default value to return if the key is not found. $sanitize: Optional. Whether to sanitize the value. Defaults to true. Returns: The input value.
file(string $key): ?array
Retrieves an uploaded file.
$key: The file key. Returns: An array containing file information, or null if the file is not found.
Checks if an uploaded file exists and was uploaded successfully.
$key: The file key. Returns: true if the file exists and was uploaded successfully, false otherwise.
isJson(): bool
Checks if the request content type is JSON.
Returns: true if the content type is JSON, false otherwise. getMethod(): string Gets the HTTP request method.
Returns: The HTTP request method. getIp(): ?string Gets the client's IP address.
Returns: The client's IP address, or null if it cannot be determined. accepts(string $contentType): bool Checks if the client accepts the given content type.
$contentType: The content type to check. Returns: true if the client accepts the content type, false otherwise. header(string $key, mixed $default = null): mixed Retrieves a header value.
PHP $authToken = $request->header('Authorization');
$key: The header key.
$default: Optional. The default value to return if the header is not found.
Returns: The header value.
get(string $key, mixed $default = null): mixed
Retrieves a GET parameter.
$key: The GET parameter key.
$default: Optional. The default value to return if the key is not found.
Returns: The GET parameter value.
post(string $key, mixed $default = null): mixed
Retrieves a POST parameter.
$key: The POST parameter key.
$default: Optional. The default value to return if the key is not found.
Returns: The POST parameter value.
json(string $key, mixed $default = null): mixed
Retrieves a value from the parsed JSON request body.
$key: The JSON key.
$default: Optional. The default value to return if the key is not found.
Returns: The JSON value.
getBody(): string
Gets the raw request body.
Returns: The raw request body.
validate(array $rules): array
Validates the request data against the given rules.
$rules: An array of validation rules.
Returns: An array of validation errors.
setUrlParams(array $params): void
Sets the URL parameters.
$params: An array of URL parameters.
param(string $key, mixed $default = null): mixed
Retrieves a URL parameter.
$key: The URL parameter key.
$default: Optional. The default value to return if the key is not found.
Returns: The URL parameter value.
all(): array
Gets all input data (GET, POST, JSON).
Returns: An array containing all input data.