vancodx/php-data-validation 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

vancodx/php-data-validation

最新稳定版本:1.0.2

Composer 安装命令:

composer require --dev vancodx/php-data-validation

包简介

VanCodX PHP Data Validation

README 文档

README

This library contains a set of static methods for validation the type of variables and arguments of functions and methods. The main goal is to improve the quality of data validation and static analysis. Each validation method has "@phpstan-assert-if-true" tag in its DocBlock comment to narrow the type of "value" argument.

Installation

Install this package with the following command:

composer require vancodx/php-data-validation

Usage

Example of validation the type of a function argument:

<?php declare(strict_types=1);

use VanCodX\Data\Validation\Validation as V;

/**
 * @param list<int> $ids
 * @return void
 */
function printIds(array $ids): void
{
    if (!V::isListLenOfIntId($ids)) {
        throw V::newArgumentException(compact('ids'));
    }
    \PHPStan\dumpType($ids); // Reports: Dumped type: non-empty-list<int<1, max>>
    echo 'IDs: ', implode(', ', $ids), "\n";
}

Example of validation the type of a variable:

<?php declare(strict_types=1);

use VanCodX\Data\Validation\Validation as V;

/**
 * @return void
 */
function printUsername(): void
{
    $username = getenv('USER');
    if (!V::isStrLen($username)) {
        throw V::newValueException(compact('username'));
    }
    \PHPStan\dumpType($username); // Reports: Dumped type: non-empty-string
    echo 'Username: ', $username, "\n";
}

Running tests

Use the following command for running the tests inside a Docker container:

docker compose up --build tests

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固