Feature #31373

Annotation to enforce validation on setter

Added by Christian Müller about 10 years ago. Updated over 9 years ago.

Status:
Rejected
Priority:
Could have
Assignee:
-
Category:
Validation
Start date:
2011-10-28
Due date:
% Done:

0%

Estimated time:
PHP Version:
Has patch:
No
Complexity:

Description

Something like @FLOW3\ValidateOnSet which you can annotate to a setter in a model. On each call the generated proxy should check the validation rules for this property before setting and if validation fails throw some error.


Related issues

Related to TYPO3.Flow - Bug #31500: Argument validation for CLI requests is not doneUnder ReviewKarsten Dambekalns2011-11-02

Actions
Related to TYPO3.Flow - Bug #31502: Validation during persistence got lost in Doctrine additionResolvedKarsten Dambekalns2011-11-02

Actions
#1

Updated by Jordy de Jong about 10 years ago

I've commited a fix to review.typo3.org

With this fix you can add the @FLOW3\ValidateOnSet annotation to your property, the proxy class builder makes sure a setter is created which enforces the validations for the property

Downside of this solution is that you have to add this validation to all your properties in all your models, maybe a generic setting is a better solution to enable this throughout your application?

#2

Updated by Mr. Hudson about 10 years ago

  • Status changed from New to Under Review

Patch set 3 of change I21c63047b3adaf3e0f72130b7f1748cbe1103e40 has been pushed to the review server.
It is available at http://review.typo3.org/6411

#3

Updated by Karsten Dambekalns about 10 years ago

  • Category set to Validation
  • Target version set to 1.1
#4

Updated by Karsten Dambekalns about 10 years ago

Two different concepts here. Christian wants to add validation to (existing) setters, Jordy created a change to annotate properties. But: why a new annotation? Why not simply add the existing Validate annotations to the setter methods?

It seems we need a clear concept first...

#5

Updated by Christian Müller about 10 years ago

Karsten Dambekalns wrote:

Two different concepts here. Christian wants to add validation to (existing) setters, Jordy created a change to annotate properties. But: why a new annotation? Why not simply add the existing Validate annotations to the setter methods?

It seems we need a clear concept first...

Yes, lets discuss this further. Actually the additional property was my idea, but I intended it on the set method. Your idea seems nice too but then you have duplicate code (annotations) in a way.

#6

Updated by Jordy de Jong about 10 years ago

I thought adding the annotation to the property would be the more logical place, so it would be next to the defined validations you want to enforce in the corresponding setter

I agree that my proposed fix isn't the ideal solution.

Personally, I'm wondering why in FLOW3 the validations aren't always enforced, by default. Either in the setter methods or before persistance. Why would you want to persist an object that doesn't match the defined validations?

#7

Updated by Karsten Dambekalns about 10 years ago

Jordy de Jong wrote:

Personally, I'm wondering why in FLOW3 the validations aren't always enforced, by default. Either in the setter methods or before persistance.

See the two related issues #31500 and #31502 - it is not intended like this.

#8

Updated by Jordy de Jong about 10 years ago

Do I understand correctly (from #31502) that validation during persistence is the intended way?

If so, I agree, because that would also have been my way of solving this.

#9

Updated by Christian Müller over 9 years ago

  • Status changed from Under Review to Rejected

Also available in: Atom PDF