The answer is yes. You need to specify your restriction on the object, not the parameter, and specify the restriction on the restriction of the class level. Somewhat true example:
config.yml
validator.my.uniquename: class: FQCN\To\My\ConstraintValidator arguments: [@service_container] tags: - { name: validator.constraint_validator, alias: ConstraintValidator }
validation.yml
FQCN\To\My\Entity: constraints: - FQCN\To\MyConstraint: ~
(no arguments to limit in this example)
My limitation
namespace FQCN\To; use Symfony\Component\Validator\Constraint ; class MyConstraint extends Constraint { public $message = 'Constraint not valid'; public function validatedBy() { return 'ConstraintValidator'; } public function getTargets() {
My constraint validator
class MyConstraintValidator extends ConstraintValidator { protected $container; function __construct($container) { $this -> container = $container; } function isValid($object, Constraint $constraint) {
source share