I'm using Symfony 1.4 to allow users to import various types of CSV files, and I've decided to consolidate validation and sanitizing of the actual contents of uploaded files into a custom validator - The custom validator would extend sfValidatorFile.
Also, when a file contains errors, I'd like to throw global errors on forms, rather than displaying them as field/local errors - and - have the ability to show many validation errors at the same time for a given import file.
I'm pretty sure I can make this work by using a Post Validator, but this doesn't seem like a great fit for a Post Validator (since I really only need knowledge of one form field in order to perform my custom validation), but more importantly, I'd like something a bit more elegant that packages all of the extra validation work into a single custom file validator.
For example, instead of:
$this->validatorSchema['file'] = new sfValidatorFile( … );
$this->validatorSchema->setPostValidator(new myFancyValidator( … ));
I'd just like to do something like:
$this->validatorSchema['file'] = new myFancyValidator( … );
...and have validation errors encountered inside myFancyValidator added to the form's collection of global errors.
I've tried a few different approaches to push errors onto the form's globalErrors from within my custom validator, but I'm missing something regarding how the various pieces of the validation puzzle fit/scope together. Any thoughts as to how to accomplish this? Dependency injection?