I've been recently (well.. two weeks ago, before my vacation) contacted by Marcelo Araujo, he asked what I would say of adding validate_ptBR extension to PECL.
The idea didn't look quite good to me, so I asked him in reply why create something for ptBR only, if you can create a general extension?
Such extension would validate all kinds of data (not just integers, strings or floats, it may include rules for SSN, credit card numbers, postal codes etc).
So here are some quick thoughts on how such an extension should look like from my pov:
- atm I see no reasons to create more than 2 (two) functions:
bool validate($rule, $data) to validate the data;
array validate_list_rules(void) to list the rules available.
- rules might be prefixed or postfixed (there should be some strict naming convention), like "ssn_ptBR", so to validate an SSN you need to call it this way:
validate("ssn_ptBR", $data);
- it seems to me that
re2c would be of great value here, to gain some more speed and maintainability;
- there might be complex cases when re2c is not enough and some manual checks would be required, so the extension should be ready to handle them;
- the extension should be easily extensible.
The only problem I see atm is the last item, but I'm going to continue working on it.
For the present I'm not ready to show you any sources (they are still to be rewritten to allow adding new rules without having to modify a bunch of files..), but I'd gladly hear your thoughts & ideas.
One of the most important questions is:
do you think such extension would be useful at all?
(especially having all of the rules implemented in PEAR/Validate)