@@ -233,11 +233,11 @@ then your validator is already registered as a service and :doc:`tagged </servic
233
233
with the necessary ``validator.constraint_validator ``. This means you can
234
234
:ref: `inject services or configuration <services-constructor-injection >` like any other service.
235
235
236
- Constraint Validators with custom options
236
+ Constraint Validators with Custom Options
237
237
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
238
238
239
- Define public properties on the constraint class for the desired configuration
240
- options:
239
+ If you want to add some configuration options to your custom constraint, first
240
+ define those options as public properties on the constraint class :
241
241
242
242
.. configuration-block ::
243
243
@@ -338,13 +338,14 @@ options:
338
338
}
339
339
}
340
340
341
- Inside the validator, options can be accessed quite simple::
341
+ Then, inside the validator class you can access these options directly via the
342
+ constraint class passes to the ``validate() `` method::
342
343
343
344
class FooValidator extends ConstraintValidator
344
345
{
345
346
public function validate($value, Constraint $constraint)
346
347
{
347
- // Access the option of the constraint
348
+ // access any option of the constraint
348
349
if ($constraint->optionalBarOption) {
349
350
// ...
350
351
}
@@ -353,8 +354,8 @@ Inside the validator, options can be accessed quite simple::
353
354
}
354
355
}
355
356
356
- Custom options can be passed to the constraints like for the ones provided by Symfony
357
- itself :
357
+ When using this constraint in your own application, you can pass the value of
358
+ the custom options like you pass any other option in built-in constraints :
358
359
359
360
.. configuration-block ::
360
361
0 commit comments