Validation class comments
| From: | Andrew Djachenko | Date: | Tue, 28 May 2002 17:07:59 +0000 |
| Subject: | Validation class comments | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-6530@lists.php.net to get a copy of this message | ||
Here some thoughts about Validation class and validation in PHP at all.
1. IMHO it must not be single huge class to validate all possible values -
integer, float, currency, date, strings, URLs, emails, number of various
credit cards an so on...
I can't imagine a lot of cases when ALL this functions will be necessary.
So such class must have pluggable architecture, and allow easily include and
exclude validation functions from working script.
2. If this class will only contain number of validation functions, it's
usefulness will be questionable. Its using will not be very differ from using
of standard PHP functions - is_integer(), is_number(), etc.
The most common case, I think, is checking of some user input from form, and I
think we must have possibility to validate entire form by single function
call. And so we come to next point...
3. I think that validation class must be build above some common type system.
Every type must have own validation function. In this case form may have some
manifest where specified variables which come from it, type of every variable
and range of legal values (in some cases). Global validation function gets
array of variable from form and this manifest as arguments. This manifest can
be represented in XML and used not only for form validation but for it
rendering too.
4. If we use type system, the next step is creating of class library with
common Object class in the top of hierarchy, and from
bool validateType(Type obj);
we get
class Type extends Object{}
bool Type::validate() where all Object successors implements own validate
function.
Andrew Djachenko