bank / mound
Validator
Requires
- php: >=7.0.0
Requires (Dev)
- phpunit/phpunit: ^5.6
This package is not auto-updated.
Last update: 2024-11-18 13:45:50 UTC
README
Validator
Installation
Add this to your composer.json file, in the require object:
"bank/mound": "version"
Alternately, clone the gatewaysitory and manually invoke composer
using the shipped
php composer.phar self-update php composer.phar install
Provider
- Converter Provider
- Filter Provider
- Validator Provider
Use Provider
Interface
public function rule(string $key): ProviderInterface;
public function group(string $key): ProviderInterface
public function attach($rule, array $options = []): ProviderInterface
public function exec(array $data, array $groups): array
Attach rule
$provider ->rule($key_name) ->attach(Rules::class, $options) ->attach(Rules::class, $options)
Group rules
$provider ->group($group_name) ->rule($key_name) ->attach(Rules::class, $options) ->attach(Rules::class, $options)
Execution
$provider->exec($data, $group_names);
Converter Provider
Convert parameters according to rules.
Returned value is converted data.
The rules that can be used are class that extends AbstractConverter.
Example
use Mound\Converter; $provider = new Converter\Provider; $data = ['test_data1' => ' test_data1']; $provider ->rule('test_data1') ->attach(Converter\Rules\Trim::class) ->endRule $data = $provider->exec($data); # ['test_data1' => 'test_data1']
Converter Rules
- Trim
- Callback
Filter Provider
Filter parameters according to rules.
Returned value is Filtering data.
The rules that can be used are class that extends AbstractFilter.
Example
use Mound\Filter; $provider = new Filter\Provider; $data = ['test_data1' => ' test_data1']; $provider ->rule('test_data1') ->attach(Filter\Rules\NotEmpty::class) ->endRule $data = $provider->exec($data); # []
Filter Rules
- NotEmpty
- Number
- Callback
Validator Provider
Validate parameters according to rules.
Returned value is error message.
The rules that can be used are class that extends AbstractValidator.
Example
use Mound\Validator; $provider = new Validator\Provider; $haystack = ['test_data']; $data = [ 'test_data1' => 'test_data1' 'test_data2' => '' ]; $provider ->rule('test_data1')->attach(Validator\Rules\NotEmpty::class) ->rule('test_data2')->attach(Validator\Rules\NotEmpty::class) ->group('in_array')->rule('test_data1') ->attach(Validator\Rules\InArray::class, [ 'haystack' => $haystack ]) ->endGroup $error = $provider->exec($data); #['test_data2' => 'can't be blank'] $error = $provider->exec($data, ['in_array']); #['test_data1' => 'is invalid', 'test_data2' => 'can't be blank']
Validator Rules
- NotEmpty
- InArray
- Callback