php - Can I change a value from within a Constraint or ConstraintValidator? -


i'm using form component in own stack, , need create constraint/validator pair.

the problem need modify value inside constraint. eg: if value 123, change 456.

how can this? need handled constraint or validator, don't want repeat logic on place.

in custom constraint, can access variable $object if it's form class constraint. should able call set methods during validation.

so, in custom constraint class:

public function gettargets()     {       return self::class_constraint;     } 

in custom constraintvalidator

 public function validate($object, constraint $constraint)     {     /*     *  thensomewhere in  code      */     if($object->getnumber() == 123){        $object->setnumber(456);     } 

some helping sources:

http://symfony.com/doc/current/cookbook/validation/custom_constraint.html

http://symfony.com/doc/current/reference/constraints/callback.html


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -