[TYPO3-50-general] MVC and ArgumentsValidators

Sebastian Kurfürst sebastian at typo3.org
Tue Jan 13 19:16:50 CET 2009


Hey everybody,

the last hours, I have taken the time to build the blog-package with  
Fluid, and in this course, I have been stumbling over some problem:

If you register an argument with
$this->arguments->addNewArgument('comment', 'F3\Blog\Domain 
\Comment');, then, while setting the Data Type, a validator is  
automatically created with the following code:

	public function setDataType($dataType) {
		$this->dataType = ($dataType != '' ? $dataType : 'Text');

		$dataTypeValidatorClassname = $this->dataType;
		if (!$this->objectManager- 
 >isObjectRegistered($dataTypeValidatorClassname))  
$dataTypeValidatorClassname = 'F3\FLOW3\Validation\Validator\\' .  
$this->dataType;
		$this->datatypeValidator = $this->objectManager- 
 >getObject($dataTypeValidatorClassname);

		return $this;
	}

However, there is a problem with it. In case the $dataType is  
something like 'Text', then, the above code correctly resolves  
F3\FLOW3\Validation\Validator\Text.

Now, imagine you have "F3\Blog\Domain\Comment" as data type (which  
will happen quite often in the future). The Object Manager says that  
the object is registered, and thus it sets $this->datatypeValidator  
_to the domain object_ - which is wrong I suppose.

Thus, in case the domain object does not implement an  
"isValidProperty" method, a fatal error happens.

Shouldn't the validator be looked up by taking the data type, and _if  
it is a valid object_, check if there is an associated *Validator for  
it - and if yes, take that one.

The attached patch implements this solution, but as I am not fully  
sure whether this is a solution to our problem (or if that's the way  
it should be) - I'm posting this to this list.

So, please comment!

Thanks and Greets,
Sebastian


-------------- next part --------------


--
Gimme five!



More information about the TYPO3-project-5_0-general mailing list