1. Go to this page and download the library: Download yuandian/validation library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yuandian / validation example snippets
use yuandian\rules\NotEmpty;
use yuandian\rules\Email;
use yuandian\rules\Scene;
// 用于配置场景验证
#[Scene("add", ['name'])]
class UserRequest {
#[NotEmpty(message: "Name cannot be empty.")]
public string $name;
#[Email(message: "Invalid email format.")]
#[NotEmpty(message: "Email cannot be empty.")]
public string $email;
}
use yuandian\rules\NotEmpty;
use yuandian\rules\Email;
use yuandian\BaseValidatorEntity;
class UserRequest extends BaseValidatorEntity {
#[NotEmpty(message: "Name cannot be empty.")]
public string $name;
#[Email(message: "Invalid email format.")]
#[NotEmpty(message: "Email cannot be empty.")]
public string $email;
}