定制 devknown/request-validator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

devknown/request-validator

Composer 安装命令:

composer require devknown/request-validator

包简介

Simple PHP Request Validator

README 文档

README

Make your apps validation easily (inspired by Laravel Validation)

the original project: progsmile/request-validator. this version adds Mysqli Adapter.

Page Index:

Suggested Links:

Quick start 🚀

<?php

$rules = [
    # firstname and lastname must exists
    # they should be alphanumeric
    # atleast 2 characters
    'firstname, lastname' => 'required|alpha|min:2',

    # max until 18 characters only
    'lastname'            => 'max:18',

    # must be an email format
    # must be unique under 'users' table
    'email'               => 'email|unique:users',

    # must be numeric
    # must exists under 'users' table
    'id'                  => 'numeric|exists:users',
    'age'                 => 'min:16|numeric',
    'info[country]'       => 'required|alpha',

    # roll[0] or roll[1] values must be in the middle 1 to 100
    'roll[0], roll[1]'    => 'numeric|between:1, 100',

    # the format must be 'm-Y.d H:i'
    'date'                => 'dateFormat:(m-Y.d H:i)',

    # it must be an image format under $_FILES global variable
    'profileImg'          => 'image',

    # the provided phone number should follow the format
    # correct: +38(123)456-12-34
    # wrong: +38(123)56-123-56
    # wrong: +39(123)456-12-34
    'phoneMask'           => 'phoneMask:(+38(###)###-##-##)',
    'randNum'             => 'between:1, 10|numeric',

    # the value must be an IP Format
    'ip'                  => 'ip',
    'password'            => 'required|min:6',

    # the value from a key 'password' must be equal to 'password_repeat' value
    'password_repeat'     => 'same:password',

    # it must be a json format
    'json'                => 'json',
    'site'                => 'url',

    # cash10 or cash25 must only have these
    # 1 or 2 or 5 or 10 or 20 or 50
    'cash10, cash25'      => 'in:1, 2, 5, 10, 20, 50',

    # the value must not have 13 or 18 or 3 or 4
    'elevatorFloor'       => 'notIn:13, 18, 3, 4',
];

$customMessage = [
   'info[country].alpha' => 'Only letters please',
   'email.required'      => 'Field :field: is required',
   'email.email'         => 'Email has bad format',
   'email.unique'        => 'This email :value: is not unique',
   'elevatorFloor.notIn' => 'Oops',
];

$v = V::make($_POST, $rules, $customMessage);

# for specific field
# you can use below code.
$v->lastname->passes();
$v->lastname->fails();

# if you're required to check everything
# and there must no failing validation
$v->passes();
$v->fails();

# get first error message
$v->first();

# get first error for `firstname`
$v->first('lastname');
$v->firstname->first();

# return first error message from each field
$v->firsts();

# get all messages (with param for concrete field)
$v->messages();
$v->messages('password');

# get all `password` messages
$v->password->messages();

# get 2d array with fields and messages
$v->raw();

# to append a message
$v->add('someField', 'Something is wrong with this');

Contributing :octocat:

Dear contributors , the project is just started and it is not stable yet, we love to have your fork requests.

Testing

This testing suite uses Travis CI for each run. Every commit pushed to this repository will queue a build into the continuous integration service and will run all tests to ensure that everything is going well and the project is stable.

The testing suite can be run on your own machine. The main dependency is PHPUnit which can be installed using Composer:

# run this command from project root
$ composer install --dev --prefer-source

A MySQL database is also required for several tests. Follow these instructions to create the database:

echo 'create database valid charset=utf8mb4 collate=utf8mb4_unicode_ci;' | mysql -u root
cat tests/dist/schema.sql | mysql valid -u root

For these tests we use the user root without a password. You may need to change this in tests/TestHelper.php file.

Once the database is created, run the tests on a terminal:

vendor/bin/phpunit --configuration phpunit.xml --coverage-text

For additional information see PHPUnit The Command-Line Test Runner.

License

PHP Request Validator is open-sourced software licensed under the GNU GPL.

devknown/request-validator 适用场景与选型建议

devknown/request-validator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 07 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 devknown/request-validator 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2022-07-02