Re: Validation class comments

From: Date: Tue, 28 May 2002 17:42:39 +0000
Subject: Re: Validation class comments
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-6535@lists.php.net to get a copy of this message
El mar, 28-05-2002 a las 19:07, Andrew Djachenko escribió: > 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... Those will be supported, the ones I initially proposed. Perhaps if people propose many others we could think on split a little the methods. > 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. Normally validation methods are small and I'm against having to include 10 files for just do the common validations. To include a 20K file (if it reach that size at some point) is better than include 3 o 4 files of 5K. > 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. There is no PHP function for validating that a number is a "normal" number :-). is_int() checks for the type and is_numeric() accepts special notations which for example databases or "humans" may not support. By the way, the number() validation I proposed supports different decimal separator (English "." or for example Spanish ","). Ok, you can say me that the function is still very short, I agree, but still very useful and needed for the multiple validation. > 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. Form classes could build over the class all the complex things they want, but IMHO the core validation classes has to be compact. > 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. I don't see the point on "bloating" the code so much. Perhaps with some examples I could see better the real need for it. I've already commited a test implementation pear/Validate/Validate.php, but it of course, could be modelled to suite the needs I maybe had overpassed. Tomas V.V.Cox

« previous php.pear.dev (#6535) next »