Validation plug-ins [message #264] |
Thu, 07 September 2006 08:57 |
janalwin
Messages: 17 Registered: May 2006 Location: Groningen
|
Junior Member |
|
|
Hallo,
I'd like to integrate my own validations in the validation class. For example for checking postcodes, telephonenumber formats etc. These are validations that occur over and over in projects and it's a waste to reimplement them in every database class.
It would by nice if you could plug-in validators into the standard validation object.
Maybe it should work this way:
- define in the subtype which validator is to be loaded: subtype="dutch_postcode"
- load the class dutch_postcode-validator in the validation class.
- do the validation with this class
We could setup some kind of repositery for exchanging validator classes between developers.
Maybe you think it's not a good idea to mess with the current validation class. It still would be nice to have a standard way to implement validators in an other way.
--
Jan Alwin de Jong
|
|
|
Re: Validation plug-ins [message #265 is a reply to message #264] |
Thu, 07 September 2006 09:34 |
AJM
Messages: 2368 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
I don't really want to mess with the current validation class as it is totally generic, but the need for custom validation rules which can be applied after the generic rules does seem like a reasonable request.
I will have a think about how this may be done to see what the possibilities are, then I will get back to you.
Off the top of my head something like an extra field in the data dictionary to identify a validation method for that field, at at runtime I could instantiate an object from a copy of 'custom_validation_class' which exists in your project directory, then pass that field's value to that method name. How does that sound?
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
|
Re: Validation plug-ins [message #268 is a reply to message #267] |
Thu, 07 September 2006 11:28 |
AJM
Messages: 2368 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
Before I can activate a method on a class there are 3 things I must know:
(a) the name of the file containing the class definition
(b) the class name
(c) the method name
I can either have (a) and (b) taken care of by providing a blank custom validation class with a fixed name to which you just add your own methods, or I can allow you to create your own class(es) with your own name(s).
The first option means that all you have to supply in the data dictionary is the method name, while the second option means that you have to supply the file name, the class name and the method name.
The first option means that you can have a separate copy of the custom validation class in your own application subdirectory so that it does not clash with anything being used in any other subdirectories, but it does mean that you can only have one custom validation class per subdirectory. This would mean that merging several different classes into one class would be a manual exercise.
The second option would be more flexible as you could have a range of different methods available in a range of different classes, and you would not have to touch any code. All you would have to do is specify in the data dictionary for each field the name of the file/class/method to be used for validation.
How does that sound?
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
Re: Validation plug-ins [message #270 is a reply to message #269] |
Thu, 07 September 2006 12:18 |
AJM
Messages: 2368 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
I think the most flexible method is to allow you to use whatever file names you like, whatever class names you like, and whatever method names you like. You then have the choice of putting several related methods in the same class, or into separate classes. I do not see the point of restricting it to one method per class, with a fixed method name of validate(). This smells of the infamous "convention over configuration" that RubyOnRails is famous for, and I wish to avoid that if I can.
You are correct in saying that I do not want to use any options that only work in PHP 5.
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|
|