Hi all,

I'm working on the new validation system and I want your thoughts about 
  a design decision I have to take.

Let's take a string validator:

   $v = new sfValidatorString(array('max_length' => 2));

Then let's try to validate a string:

   $ret = $v->validate('t');

Here, $ret is 't'.

Now, if I do:

   $ret = $v->validate('foo');

What happens?

1 - The validator throws a sfValidatorException:

   throw new sfValidatorException('String is too long');


2 - The validator returns a sfValidatorError object:

   return new sfValidatorError('String is too long');

3 - The validator returns false or another "magic" value:

   return false;

3 is not very good because then I can't return false as a valid value 
(same goes for null or whatever other value).

My preference goes to the exception but PHP exceptions are quite 
inflexible, the message has to be a string, so if I want to return 
several error messages, I can't:

   throw new sfValidatorException(array('String is too long', 'foo is 
not a valid string'));

Here is a typical usage:

try
{
   $ret = $v->validate('foo');
}
catch (sfValidatorException $e)
{
   // do something with the error
}

The sfValidatorError usage looks good but the user code looks less "clean":

$ret = $v->validate('foo');
if ($ret instanceof sfValidatorError)
{
   // do something with the error
}

It's less clean because if you forget to check the return value, you can 
have some weird behaviors in your code and debugging can then be much 
harder.

Thanks for your ideas,
Fabien


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/symfony-devs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to