$data = ['a' => ' Foo '];
print_r(prepare($data)->map('trim')->getData()); // ['a' => 'Foo']
$data = ['a' => 'foo', 'b' => 'bar'];
print_r(prepare($data)->apply(['a' => 'ucfirst'])->getData()); // ['a' => 'Foo', 'b' => 'bar']
$data = ['name' => ' foo ', 'age' => null, 'test' => false, 'quatz' => null];
print_r(prepare($data)->allowOnly(['name'])->getData()); // ['name' => ' foo ']
$data = [];
print_r(prepare($data)->applyDefaults(['name' => 'Foo'])->getData()); // ['name' => 'Foo']
$data = ['name' => ' foo ', 'age' => null, 'test' => false, 'quatz' => null];
print_r(prepare($data)->filter()->getData()); // ['name' => ' foo ']
$data = ['name' => ' foo ', 'age' => null, 'test' => false, 'quatz' => null];
print_r(prepare($data)->filterBy(function($v, $k) {
return !empty($v);
})->getData()); // ['name' => ' foo ']
$rules = [
'name' => 'string',
'age' => 'int(40, 100)',
'foo' => 'string(a+b+)',
'bar' => 'string(5)'
];
$data = ['name' => 'Foo', 'age' => 42, 'foo' => 'abb', 'bar' => 'quatz'];
print_r(prepare($data)->filterByRules($rules)->getData()); // ['name' => 'Foo', 'age' => 42, 'foo' => 'abb', 'bar' => 'quatz']
$pattern = [
'name' => '#^\w+$#',
'age' => '#\d{2}#'
];
$data = ['name' => 'Foo', 'age' => 42];
print_r(prepare($data)->filterByPattern($pattern)->getData()); // ['name' => 'Foo', 'age' => 42]
Rules are one of
<type>(<min>, <max>)
whereby<min>
and<max>
are integers<type>(<limit>)
whereby<limit>
is an integer<type>(<pattern>)
whereby<pattern>
is a valid regex- or only
<type>
for <type>
the following types are valid:
numeric
int(eger)
float|double|real|decimal
bool(ean)
string
array
object|class