that could be a good solution, the sfValidatorException having a constructor
wrapping it's parameters into an array in exception members, and there could
be a convenience method ->getMessage that would wrap all the sentences in
one.


class sfValidator
{
  protected $errors;

  public function __construct()
  {
    $this->errors = new sfValidationException();
  }

  protected function validate()
  {
    if ($this->errors->count())
    {
       throw $this->errors;
    }
  }

  .....

class xxxValidator extends sfValidator
{
function validate($str)
{
  if (strlen($str) < 10) $this->errors->addError('String too short');
  if (strtolower($str) != $str) $this->errors->addError('String must be
lowercase');

  return parent::validate();
}

Can an exception implements interfaces? then just make the
sfValidationException implement ArrayAccess, Countable and Iterator, to be
the most flexible it can.


2007/10/1, Carl Vondrick <[EMAIL PROTECTED]>:
>
>
> On Sunday, September 30, 2007, Fabien POTENCIER wrote:
> > 1 - The validator throws a sfValidatorException:
> >
> >    throw new sfValidatorException('String is too long');
>
> I like the first method myself.
>
> If you wanted to add more error messages, couldn't you also do:
>
> $e = new sfValidatorException('String is too long');
> $e->addError('Stars are not aligned.');
> throw $e;
>
> then...
>
> try { ... }
> catch (sfValidatorException $e)
> {
>   $errors = $e->getErrors(); // returns array of all errors.
> }
>
>
> >
>


-- 

Best regards

Romain

--~--~---------~--~----~------------~-------~--~----~
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