承接 axm/validation 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

axm/validation

最新稳定版本:1.0.9

Composer 安装命令:

composer require axm/validation

包简介

Simple, validation of rules

README 文档

README

Total Downloads Latest Stable Version License

Certainly! Here's comprehensive documentation for the Validator class along with examples of how to use it. This documentation is formatted for GitHub:

Validator Class

The Validator class is a versatile tool for data validation in PHP applications. It allows you to define validation rules and check if data meets those rules. This documentation provides an in-depth guide to using the Validator class.

Table of Contents

  1. Class Overview
  2. Installation
  3. Basic Usage
  4. Validation Rules
  5. Advanced Usage
  6. Examples
  7. Contributing
  8. License

1. Class Overview

The Validator class provides the following features:

  • Validation of data against user-defined rules.
  • Support for custom validation rules.
  • Rule chaining for complex validation scenarios.
  • Detailed error reporting with customizable error messages.

2. Installation

To use the Validator class, follow these steps:

composer require axm/validation

3. Basic Usage

Here's a simple example of how to use the Validator class:

use Axm\Validation\Validator;

$rules = [
    'username' => 'required|string|min:5|max:20',
    'email' => 'required|email',
];

$data = [
    'username' => 'john_doe',
    'email' => 'johndoe@example.com',
];

$validator = Validator::make($rules, $data);

if ($validator->validate()) {
    echo "Data is valid!";
} else {
    $errors = $validator->getErrors();
    print_r($errors);
}

4. Validation Rules

The Validator class supports a variety of validation rules, including required, string, email, min, max, and custom rules. You can chain rules together using the | separator.

Available Rules
  • required: Ensures the field is present and not empty.
  • string: Checks if the field is a string.
  • email: Validates the field as an email address.
  • min:value: Checks if the field's length or value is greater than or equal to value.
  • max:value: Checks if the field's length or value is less than or equal to value.
  • Custom Rules: You can define your own custom validation rules.

5. Advanced Usage

Custom Validation Rules

You can create custom validation rules by defining a class that implements the Axm\Validation\Rules\RuleInterface. Here's an example:

use Axm\Validation\Rules\RuleInterface;

class CustomRule implements RuleInterface
{
    public function validate($value, array $parameters = []): bool
    {
        // Implement your custom validation logic here.
        return /* validation result */;
    }

    public function message(): string
    {
        // Define a custom error message for this rule.
        return 'Custom validation failed.';
    }
}
Adding Custom Rules

To add custom rules to the Validator, use the addRules method:

$customRules = [
    'custom_rule' => CustomRule::class,
];

$validator->addRules($customRules);

6. Examples

Here are more examples of how to use the Validator class:

Example 1: Conditional Validation
$rules = [
    'password' => 'required|string|min:8',
    'confirm_password' => 'required|string|same:password',
];

$data = [
    'password' => 'mysecurepassword',
    'confirm_password' => 'mysecurepassword',
];

$validator = Validator::make($rules, $data);
Example 2: Unique Rule
$rules = [
    'email' => 'required|string|unique:users,email',
];

$data = [
    'email' => 'johndoe@example.com',
];

$validator = Validator::make($rules, $data);

7. Contributing

If you want to contribute to the Validator class, please follow the contributing guidelines.

8. License

The Validator class is open-source software licensed under the MIT License.

This documentation should help you get started with the Validator class and demonstrate various use cases. For more details and advanced usage, refer to the class source code and examples provided in the GitHub repository.

Feel free to adapt and expand upon this documentation as needed for your project.

axm/validation 适用场景与选型建议

axm/validation 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 126 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 05 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「framework」 「microframework」 「php」 「rest」 「router」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 axm/validation 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 axm/validation 我们能提供哪些服务?
定制开发 / 二次开发

基于 axm/validation 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 126
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 16
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-28