chanmix51 / parameterjuicer Goto Github PK
View Code? Open in Web Editor NEWValidator and cleaner for parameter sets.
License: Other
Validator and cleaner for parameter sets.
License: Other
The project has been in RC for almost 2 month, would it be ok to release it as stable?
Hi there, it's me again!
I found a weird case to handle : I wanted to use a Juicer on a field and when I wrote tests I tried with a null value and found that it throws a php exception about the clean process.
$validator
->addField('foo', true)
->addJuicer('foo', (new \Chanmix51\ParameterJuicer\ParameterJuicer)
->addField('bar', true)
->addValidator('bar', function($v) {
if ("baz" !== $v) {
throw new \Chanmix51\ParameterJuicer\ValidationException('error.');
}
})
)
;
$data = [
'foo' => null,
];
$data = $validator->squash($data);
// PHP Fatal error: Uncaught TypeError: Argument 1 passed to Chanmix51\ParameterJuicer\ParameterJuicer::clean() must be of the type array, null given in /vendor/chanmix51/parameter-juicer/sources/lib/ParameterJuicer.php:348
I think that this case should be handle, what do you think?
I didn't find a way to compare two fields. For example if you have an array with a min
and max
value, it could be useful to check that max
is greater than min
in its validation.
Did you already though about that case and have any idea?
It could be nice to have a way to throw the ValidationException
on the first validation fail encountered, instead of stacking all the validation errors. In this way, I would be able to use the validation as following (following this order):
...
->addValidator('scope', 'Validation\isNotBlank')
->addValidator('scope', 'Validation\isArray')
->addValidator('scope', Validation\belongsTo(['foo', 'bar', 'baz']))
...
Almost everywhere it is possible to use a callable to clean, validate, etc but not for the default value.
I think it can be a good think to use a callable here to because a default value can take some resources like computing a uuid
. Using a callable we will have a "lazy loaded" default value.
What do you think ?
Having the name of the field validated can help to construct a nicer error message.
This is maybe the behaviour you wanted in the fixtures you implemented https://github.com/chanmix51/ParameterJuicer/blob/master/sources/tests/Fixtures/PikaChuJuicer.php#L44 $name
field does not exists.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.