[TYPO3-mvc] Custom validators your opinion please

Nikolas Hagelstein lists at shr-now.de
Thu Feb 25 13:50:36 CET 2010


Hi,

as we all know extbase shippes  with a bunch of validators.
Adding custom validators is a pretty straight forward.

But things get slightly complicated if validations become more complex.

E.g. let's assume I would like to validate a controller argument for
syntactical correctness and do some logical validation e.g. check against
database or webservice subsequently.

A task like this can be  done either by a huge custom validator or within
the target action using something like:

----
If (..insert bunch of complex conditions here  == FALSE ) :
	$error =
t3lib_div::makeInstance('Tx_Extbase_MVC_Controller_ArgumentError',
'whatever');
	
$error->addErrors(array(t3lib_div::makeInstance('Tx_Extbase_Validation_Error
', 
		'whatever description' 'whatever code')));

	$this->request->setErrors(array($error));

	$referrer = $this->request->getArgument('__referrer');

	$this->forward($referrer['actionName'], $referrer['controllerName'],
		$referrer['extensionName'], $this->request->getArguments());
----

I am currently wondering how to handle such cases. I.e. a. use a custom
validator or b. handle it within the target action.

Pro a:

Target action stays clearly arranged

Contra a:
Custom validators aren't aware of the full context (e.g. other request
parameters etc.).

Pro b:
Results from the validation can be used witin further processing.
Target action is aware of the whole request context

Contra b:
Things aren't that much clearly arranged.
Reusuability is an issue.

What do you think?

Cheers,
Nikolas



 



More information about the TYPO3-project-typo3v4mvc mailing list