azly / kphp_validator
KPHP 验证器
v0.0.1
2022-12-18 22:38 UTC
Requires
- php: >=7.0
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();
安装
要安装此库,请按照以下步骤操作:
git clone https://github.com/VKCOM/kphp
composer require azly/kphp_validator:dev-master
快速开始
-
使用 composer 创建 vendor/autoload.php
-
创建 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);