承接 einlinuus/php-validator 相关项目开发

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

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

einlinuus/php-validator

最新稳定版本:1.0.0

Composer 安装命令:

composer require einlinuus/php-validator

包简介

Minimal library to validate and transform user input

README 文档

README

Capabilities

  • Check for datatype
  • Check for length / amount
  • Check for regex
  • Check for min / max entries in array
  • Check for unique entries in array
  • Clean strings (remove double spaces, trim, etc.)
  • Check for valid email format
  • Check for valid URL format
  • Check for specific array shape
  • Custom validation functions
  • Custom transformation functions

Use cases

  • Validate user input
  • Validate API input
  • Transform input (e.g. convert IDs to objects)

Installation

This package can be installed via composer:

composer require einlinuus/php-validator

New to composer?

Composer is a dependency manager for PHP. Composer can install this package from the packagist.org registry. Once installed, you'll find a vendor directory in your project.

You can import all required files by importing the autoload.php file created by composer: require_once __DIR__ . "/vendor/autoload.php"; With the autoload-file included in your project, you now have access to all classes and functions provided by this package.

Usage

Simply create a new instance of the Validator class and pass the input data to the constructor.

Next, chain the validation methods inside a try-catch block. If any of the validation methods fail, a ValidatorException will be thrown.

After the validation methods, you can get the output data by calling the get() method. The output data is your input data transformed by the transformation methods. If no transformation methods are used, the output data will be the same as the input data.

$input = "hello world";

$v = new Validator($input);
try {
    $v->isString("Input must be a string")
        ->isLowercase("Input must be lowercase")
        ->min(3, "Input must be at least 3 characters long")
        ->max(12, "Input must be at most 10 characters long");
} catch (ValidatorException $e) {
    die("Invalid: " . $e->getMessage());
}

$validated = $v->get();
var_dump($validated); // string(11) "hello world"

You can find more examples in the examples folder.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2024-02-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固