satomif/extra-aura-filter-module

Aura过滤器2.x附加自定义规则模块

2.0.2 2017-12-08 00:05 UTC

This package is not auto-updated.

Last update: 2024-09-15 04:00:15 UTC


README

Build Status

ExtraAuraFilterModule

https://github.com/auraphp/Aura.Filter/blob/2.x/docs/custom.md

这是一个用于添加自定义规则的Module。

模块安装

$config = require dirname(dirname(__DIR__)) . '/var/conf/validate.php';

$this->install(new ExtraAuraFilterModule($config));

配置(validate.php)

$config = [
    'mbstrlen-max' => \Satomif\ExtraAuraFilterModule\Filter\MbStrlenMax::class
];

return $config;

如何验证

use ValidationInject;

$mbString = 'こんにちは!世界2!';
$this->filter->validate('var_name')->is('mbstrlen-max', 9);
$data = ['var_name' => $mbString];
$fail = $this->filter->apply($data);
if (! $fail) {
  $msgs = (string) $this->errorString;
}