azly/kphp_validator

v0.0.1 2022-12-18 22:38 UTC

This package is auto-updated.

Last update: 2024-09-12 00:44:38 UTC


README

KPHP 验证器

实现的功能

如果您想使用 KPHP 编译项目,可以使用以下约束来验证数据:

Length($min ::: int = -1, $max ::: int = -1, $exact ::: int = -1);
Type($type ::: string);
NotBlank();
Email();

安装

要安装此库,请按照以下步骤操作:

  1. 下载 KPHP 源代码
git clone https://github.com/VKCOM/kphp
  1. 下载 KPHP 验证器库
composer require azly/kphp_validator:dev-master
  1. 从源文件编译 KPHP

快速开始

  1. 使用 composer 创建 vendor/autoload.php

  2. 创建 index.php 并在此处编写:

<?php
require_once __DIR__ . '/vendor/autoload.php';

// Create a list with constraints
$ConstraintListFactory = new ConstraintListFactory();

// Create a validator
$validatorFactory = new ValidatorFactory();

// Example of create a constarints
$constraintList->addConstraint("name", new Type("string"));
$constraintList->addConstraint("email", new Email());

// Validation
$validator->validate($form, $constraintList);