@@ -38,54 +38,27 @@ use it as an annotation/attribute in other classes.
3838
3939 The ``#[HasNamedArguments] `` attribute was introduced in Symfony 6.1.
4040
41- You can use ``#[HasNamedArguments] `` or ``getRequiredOptions() `` to make some constraint options required:
41+ You can use ``#[HasNamedArguments] `` or ``getRequiredOptions() `` to make some constraint options required::
4242
43- .. configuration-block ::
44-
45- .. code-block :: php-annotations
46-
47- // src/Validator/ContainsAlphanumeric.php
48- namespace App\Validator;
49-
50- use Symfony\Component\Validator\Constraint;
51-
52- /**
53- * @Annotation
54- */
55- class ContainsAlphanumeric extends Constraint
56- {
57- public $message = 'The string "{{ string }}" contains an illegal character: it can only contain letters or numbers.';
58- public $mode;
59-
60- public function getRequiredOptions(): array
61- {
62- return ['mode'];
63- }
64- }
65-
66- .. code-block :: php-attributes
43+ // src/Validator/ContainsAlphanumeric.php
44+ namespace App\Validator;
6745
68- // src/ Validator/ContainsAlphanumeric.php
69- namespace App\ Validator;
46+ use Symfony\Component\ Validator\Attribute\HasNamedArguments;
47+ use Symfony\Component\ Validator\Constraint ;
7048
71- use Symfony\Component\Validator\Attribute\HasNamedArguments;
72- use Symfony\Component\Validator\Constraint;
49+ #[\Attribute]
50+ class ContainsAlphanumeric extends Constraint
51+ {
52+ public $message = 'The string "{{ string }}" contains an illegal character: it can only contain letters or numbers.';
53+ public string $mode;
7354
74- #[\Attribute ]
75- class ContainsAlphanumeric extends Constraint
55+ #[HasNamedArguments ]
56+ public function __construct(string $mode, array $groups = null, mixed $payload = null)
7657 {
77- public $message = 'The string "{{ string }}" contains an illegal character: it can only contain letters or numbers.';
78-
79- public string $mode;
80-
81- #[HasNamedArguments]
82- public function __construct(string $mode, array $groups = null, mixed $payload = null)
83- {
84- parent::__construct([], $groups, $payload);
85-
86- $this->mode = $mode;
87- }
58+ parent::__construct([], $groups, $payload);
59+ $this->mode = $mode;
8860 }
61+ }
8962
9063Creating the Validator itself
9164-----------------------------
0 commit comments