SitePoint Sponsor |
|
User Tag List
Results 1 to 1 of 1
Thread: Extending validation
-
Aug 15, 2007, 08:37 #1
- Join Date
- Mar 2003
- Location
- Halifax
- Posts
- 191
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Extending validation
I was wondering whether anyone could help me.
Sometime ago I created all my validation using the strategy pattern which worked great.
As the application has evolved I realized there was an obvious requirement to group validation together and therefore I created some specific validators (user, payment) which aggregated the base validator classes.
Now I find myself with the need to run different validation routines based on certain conditions, for instance validating cards in different ways.
One idea I had was to create an array of rules, and return the required fields and the necessary validation object.
My quandry now is how I would then add the relevant parameters to returned object:
Code:class PaymentValidatorRules { private $rules = array(); function __construct($type=NULL) { $this->loadPaymentValidatorRules($type); } private function loadPaymentValidatorRules($type=NULL) { //Set up the validator object $validator = new Payment_Validator; //Set default rules $this->rules[] = array('fields' => array('type'), 'validator' => $validator); }
Bookmarks