Hi there again,
Thanks for nice filter tool.
Will try to be short, here is my problem:
What
$validator = new Validator();
$validator->required('title')->string()->lengthBetween(0, 255);
$validator->optional('slug')->string()->lengthBetween(0, 255);
$filter = new Filter();
$filter->value('slug')->slug('title');
$data = [
'title' => 'Test title',
'slug' => 'test-slug',
];
$result = $validator->validate($data);
$values = $filter->filter($result->getValues());
var_dump($values);
/*
[
'title' => 'Test title',
'slug' => 'testslug'
]
'slug' => 'testslug' instead of 'slug' => 'test-slug' because slug filter is call any time even if `slug` value is set.
*/
What is expected
$validator = new Validator();
$validator->required('title')->string()->lengthBetween(0, 255);
$validator->optional('slug')->string()->lengthBetween(0, 255);
$filter = new Filter();
$filter->value('slug')->skip(function ($value) { return !empty($value); })->slug('title');
$data = [
'title' => 'Test title',
'slug' => 'test-slug',
];
$result = $validator->validate($data);
$values = $filter->filter($result->getValues());
var_dump($values);
/*
[
'title' => 'Test title',
'slug' => 'test-slug'
]
*/
My suggestion is to add something that will give a possibility to skip filtering when value for filtered key is set, or maybe for any condition.
I know that filter is call to filter, but without own code we cannot obtain wondered behavior.
If I miss something please share a link to solution.
Thanks!
Hi there again,
Thanks for nice filter tool.
Will try to be short, here is my problem:
What
What is expected
My suggestion is to add something that will give a possibility to skip filtering when
valuefor filtered key is set, or maybe for any condition.I know that filter is call to
filter, but without own code we cannot obtain wondered behavior.If I miss something please share a link to solution.
Thanks!