[TYPO3-50-general] MVC and ArgumentsValidators
Robert Lemke
robert at typo3.org
Fri Jan 16 13:39:32 CET 2009
Hi Sebastian,
Am 13.01.2009 um 19:16 schrieb Sebastian Kurfürst:
> 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.
yes, that's a bug / misimplementation.
> 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.
yes, that was always the plan:
- if the dataType is an unqualified class name, FLOW3 will try to
find a standard validator with that name:
$dataType == 'Text' => $validatorClassName = 'F3\FLOW3\Validation
\Validator\Text'
- if the dataType is a fully qualified class name, FLOW3 will try to
find a custom validator:
$dataType == 'F3\TYPO3\Domain\Model\Content\Page' =>
$validatorClassName == 'F3\TYPO3\Domain\Model\Content\PageValidator'
BTW, does anything speak against putting the Domain Model's validators
into the same namespace (like above)? An alternative (but more
difficult to resolve) would be:
$dataType == 'F3\TYPO3\Domain\Model\Content\Page' =>
$validatorClassName == 'F3\TYPO3\Domain\Validator\Content\Page'
So, the current implementation is just wrong, we'll need to change that.
Cheers,
robert
More information about the TYPO3-project-5_0-general
mailing list