Re: Validate package API proposal
| From: | Bertrand Mansion | Date: | Sun, 16 Feb 2003 20:03:14 +0000 |
| Subject: | Re: Validate package API proposal | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-13383@lists.php.net to get a copy of this message | ||
<paj@pearfr.org> wrote :
> On Sun, 16 Feb 2003 18:52:36 +0100
> Bertrand Mansion <bmansion@mamasam.com> wrote:
>
>> Hi Pierre,
>>
>> The Validate package could be used with QuickForm to validate form
>> data. At the moment, QuickForm can use it successfully, but because
>> the Validate methods API is always different from one method to
>> another, there are only a small number of methods that QuickForm can
>> work with.
>
>
>> So, if, instead of using function rib($aCodeBanque, $aCodeGuichet,
>> $aNoCompte, $aKey), you use an array with 4 keys as first parameter,
>> that would make it easy for QuickForm users to use the Validate
>> package.
>
> The problem is these value could change a lot from a bank to another,
> with no real constant string format, but these different values are
> always there.
I mean you could also pass an array as parameter, like this:
$rib = array('aCodeBanque' => 12,
'aCodeGuichet' => 131,
'aNoCompte' => 43,
'aKey' => 12);
$validate = Validate_FR::rib($rib);
This could be a standard so the developer using Validate would always know
how parameters should be passed to the methods.
When multiple values need to be passed, you could use an array and when the
method only needs one, you could use a scalar. Same goes for options.
> But you can pass an array as the 1st argument which contains each
> key/value pair. This is implemented in every function to allow the
> Validate::multiple() calls.
I just looked at this method. It seems you MUST pass it an array, this will
be a problem if I just want to validate a scalar like for instance an email..
> Multiple allows you to make a single call with as many values to check
> you need.
>
>> In summary, I would suggest that you use functionName($valuesToTest,
>> $optionsForValidation) as a common access to all validation functions.
>
> Does multiple fit your needs ?
Actually, no. I see two possible solutions. The first one would be to
rewrite each methods while they are not too many so that they only accept 2
parameters (which is IMO enough for validation). The second one would be to
write an abstraction method that will call the right method in the right
package. With this solution, you will need to pass the country and the
validation method name into your options array.
I would prefer the first one of course, it's easier to use and should be
much faster to process.
Let me know if you think this is feasible and if you need help with this.
Thanks,
Bertrand Mansion
Mamasam