承接 district5/validator 相关项目开发

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

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

district5/validator

最新稳定版本:2.1.0

Composer 安装命令:

composer require district5/validator

包简介

District5 Validator Library

README 文档

README

codecov

District5 Validator Library

About

This library provides the skeletons to support validators.

Installing

This library requires no other libraries.

composer require district5/validator

Usage

Validator

To create an implementation of a validator you will need to implement the \District5\Validator\ValidatorInterface interface or extend the provided Abstract Class \District5\Validator\AbstractValidator.

An example validator for a StringLength validator might look as follows:

use \District5\Validator\AbstractValidator;

class StringLengthValidator extends AbstractValidator
{
    protected $errorMessages = [
        'notString' => 'Value is not a string',
        'tooShort' => 'Value is below the minimum string length',
        'tooLong' => 'Value exceeds the maximum string length'
    ];

    private $min;

    private $max;

    public function __construct(int $min, int $max)
    {
        parent::__construct();

        $this->min = $min;
        $this->max = $max;
    }

    public function isValid($value): bool
    {
        if (!is_string($value)) {
            $this->setLastErrorMessage('notString');
            return false;
        }

        $len = strlen($value);

        if ($len > $this->max) {
            $this->setLastErrorMessage('tooLong');
            return false;
        }

        if ($len < $this->min) {
            $this->setLastErrorMessage('tooShort');
            return false;
        }

        return true;
    }
} 

Issues

Log a bug report!

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: mit
  • 更新时间: 2024-02-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固