roy404/request
Composer 安装命令:
composer require roy404/request
包简介
Request class provides an object-oriented way to interact with the current HTTP request being handled by your application as well as retrieve the input, and files that were submitted with the request.
README 文档
README
Install the bundle using Composer:
composer require roy404/request
DOCUMENTATION
This PHP class is designed to handle HTTP requests and provide validation and error handling functionalities. It extends the Blueprints class and provides methods for validating inputs, accessing request data, and checking for errors.
Usage
-
Instantiate the class: Create an instance of the
Requestclass to access its methods.$request = new Request(); # Access request data: Use the input(), json(), query(), file(), post(), inputs(), has(), method(), only(), and except() methods to access request data. $email = $request->input('email'); $inputs = $request->inputs(); $hasEmail = $request->has('email'); $method = $request->method(); $filteredInputs = $request->only(['email', 'name']); $filteredInputs = $request->except(['password']);
-
Validate inputs: Use the validate() method to specify validation rules and the isSuccess() and isFailed() methods to check if validation was successful.
$request->validate([ 'email' => 'required|email', 'file' => 'required|file|extensions:xlsx,pdf|max:200', 'images' => 'required|image|dimensions:max_width=1800,max_height=1500' ]); if ($request->isSuccess()) { // Validation successful } else { // Validation failed $errors = $request->errors(); }
-
Set custom error messages: Use the message() method before the isSuccess() and isFailed() to set custom error messages for validation rules.
$request->message([ 'email' => [ 'required' => 'Email address is required.' ], 'file' => [ 'required' => 'Please upload a file.' ] ]);
Available Methods
inputs(): array: Get all input values.input(string $name): mixed: Get the value of a specific input.has(string $key): bool: Check if an input exists.method(): string: Get the HTTP request method.only(array $input_keys): array: Get only the specified input values.except(array $input_keys): array: Get all input values except the specified keys.errors(bool $force_all = false): array: Get validation errors.error(string $key): mixed: Get the error message for a specific input key.isMatched(string $key, mixed $value): bool: Check if the input value matches the specified value.isSuccess(): bool: Check if validation was successful.isFailed(): bool: Check if validation failed.validate(array $array): self: Set validation rules.message(array $array): void: Set custom error messages.
Validation Rules
image: Ensures that the input is a valid image file, such as JPEG, PNG, GIF, SVG, or WEBP.file: Validates that the input is a valid file upload.required: Checks that the input is not empty.array: Verifies that the input is an array.null: Checks that the input is null.numeric: Ensures that the input is a numeric value.integer: Checks that the input is an integer.string: Verifies that the input is a string.email: Validates that the input is a valid email address.password: Validates that the input is a valid password.confirmed: Checks that the input value matches another field (typically used for password confirmation).mimes: Specifies the allowed MIME types for file uploads, such as JPEG, PNG, PDF, etc.extensions: Specifies the allowed file extensions for file uploads, such as pdf, xlsx, etc.max: Specifies the maximum file size in MB allowed for file uploads or the maximum characters length for strings.min: Specifies the minimum characters length for strings.dimensions: Validates the dimensions (width and height) of an image file, enforcing minimum or maximum width and height requirements for images. It supports options likemax_width,max_height,min_width,min_height,width, andheight.
roy404/request 适用场景与选型建议
roy404/request 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 205 次下载、GitHub Stars 达 3, 最近一次更新时间为 2024 年 02 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「plugins」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 roy404/request 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 roy404/request 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 roy404/request 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Alfabank REST API integration
dcat-admin plugins loginCaptcha.
WordPress theme framework
Manages the auto-installation of a mu-plugin for a plugin.
Allows you to use 2Checkout payment gateway with the WooCommerce plugin.
Zero-dependency raw PHP DNS resolver, domain-ownership verification, and intoDNS/MxToolbox-style diagnostics. Queries authoritative nameservers directly over sockets — never trusts the recursive cache for ownership checks.
统计信息
- 总下载量: 205
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-02-18