phpatom/validation

psr7请求的验证库

v0.1.1 2020-09-27 18:45 UTC

This package is auto-updated.

Last update: 2024-09-29 05:36:31 UTC


README

验证

Status License

一个直观的PSR-7服务器请求验证库

📝 目录表

先决条件

  • PHP 7.3 +
  • Composer

安装

推荐通过Composer安装

composer require phpatom/validation

测试安装

composer test

编码风格

./vendor/bin/phpcs

入门

$v = new \Atom\Validation\Validator();
$v->assert("title")->is()->present()->filled()->alphaNumeric()->between(10,255);
$v->assert("post_id")->onQueryParams()->is()->present()->filled()->and()->follows(new PostExistenceConstraint());
$v->assert("content")->is()->presentAndFilled();
$v->assert("featured_image")->on(\Atom\Validation\Scope::files())->is()->present()->file()->image()->lessThan(200000);
$v->assert("created_at")->is()->present()->filled()->date()->and()->before("now");
  
$v->validate($request); // throw ValidationException   
//OR
$v->check($request);
if($v->failed()){
   return $v->errors();
}

使用

贡献

欢迎Pull requests。对于重大更改,请先创建一个问题来讨论您想更改的内容。

请确保适当地更新测试。

✍️ 作者