auraphp / Aura.Filter

Validate and sanitize arrays and objects.
MIT License
159 stars 33 forks source link

Add multidimensional support #131

Closed jakejohns closed 5 years ago

jakejohns commented 7 years ago

RE: #117

Here's a shot at a start for this. ... ... maybe? Any thoughts?

use Aura\Filter\FilterFactory;

$data = [
    'id' => 'asd',
    'user' => [
        'name' => 'Foo',
        'age' => 'asd',
    ],
    'url' => 'http://example.com'
];

$filter_factory = new FilterFactory();
$filter = $filter_factory->newSubjectFilter();

$filter->validate('id')->is('int');
$filter->validate('url')->is('url');

$user_spec = $filter->subfilter('user'); // add a "SubSpec"
$user_filter = $user_spec->filter();  // Get the "SubSpec" SubjectFilter

$user_filter->validate('given-name')->isNotBlank();
$user_filter->validate('age')->is('int');
$user_filter->sanitize('gender')->toBlankOr('strlen', 1)->useBlankValue('M');

$valid = $filter->apply($data);
harikt commented 6 years ago

We need a few tests.

Oh and some docs.

harikt commented 5 years ago

I am merging this. I will see how I can move this forward.