Re: Validation functions
| From: | Tomas V.V.Cox | Date: | Sat, 22 Jun 2002 16:20:42 +0000 |
| Subject: | Re: Validation functions | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-7291@lists.php.net to get a copy of this message | ||
Alexander Merz wrote:
>
> Michael Dransfield wrote:
> > return new PEAR_Error('unable to validate - no
> > function', 2,PEAR_ERROR_TRIGGER, E_USER_NOTICE);
> > return new PEAR_Error('Unable to validate - no file', 1,
> > PEAR_ERROR_TRIGGER, E_USER_NOTICE);
>
> If you change this to
> PEAR::raiseError( ...
> and using constants for the errorcode (VALIDATE_UK_ERROR_*)
> i would be inspred! :-)
Please listen, unless we change the way validation functions work, we
are not going to introduce PEAR Errors. I started time ago to change the
class to return error codes instead of bool and wasn't happy with the
result and I don't think that will be ever commited.
I sent a private message to Pierre with this idea:
~~~~~~~~~~~~~~~~~~~~
BTW I would like to comment you my idea on error reporting. I started to
change the class and have half the way the thing done. Basically
consists on change the actual bool returned values (on valid or not) to
this:
/*
Constants defining the type of error comming from a validation method
*/
define('VAL_OK', 1); // Valid subject
define('VAL_E_INVALID', -1); // Invalid subject error
define('VAL_E_OUTOFRANGE', -2); // Subject out of the suplied range
define('VAL_E_FAILDOMAIN', -3); // Failed in domain validation
For people who doesn't care on what really happened can do a:
if (Validate::ssn(123456789) < 0) {
die('Oops wrong SSN number');
}
For people who wants to return to the user a fine grained error
reporting, could do:
if (($res = Validate::number(100, null, null, 1, 10)) < 0) {
if ($res == VAL_E_OUTOFRANGE)
die("Only values between 1 and 10 are allowed");
else
die("You have to submit a number here");
}
~~~~~~~~~~~~~~~~~~~~
That's too bloat in my opinion (but please give your ideas if have
them). It will be even more bloated if we change the class to use PEAR
errors:
if (PEAR::isError($error = Validate::number(...)) {
die("Validation failed");
}
We are not going to try to build the error messages for the class
(because of its I18N character), so the PEAR Error will cointain just
nothing useful.
Please don't buzz more with that ;-)
Tomas V.V.Cox
PS.- Michael, please post the code somewhere to take a look on how to
add it.