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)
Best regards, Thomas Koch
[1] http://www.php.net/manual/en/ref.filter.php
[2] http://ez.no/ezcomponents
[3] http://ez.no/doc/components/view/trunk/(file)/introduction_UserInput.html
But it's main point is a bit different.
Being one of the original author of the Validate package, I think having the locale sub packages as extension makes little sense. The rules for locale validation are too volatile and they often rely on extern data (DB, services, etc.).
However, it makes a lot of sense to replace the main Validate package by ext/filter. That's where I think filter evolution should go (and I'm really sad that I'm not able to do it only because of political problems). It is also why I pushed filter so hard and also tried to make it more flexible (and in some way failed...).
Amazingly what you propose is nearly identical to what I did in Validate (the main package) and nearly identical (but not flexible enough) to what I like to have in filter.