File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -30,19 +30,35 @@ First you need to create a Constraint class and extend :class:`Symfony\\Componen
30
30
{
31
31
public $message = 'The string "{{ string }}" contains an illegal character: it can only contain letters or numbers.';
32
32
public $mode = 'strict'; // If the constraint has configuration options, define them as public properties
33
+
34
+ public function getRequiredOptions(): array
35
+ {
36
+ return ['mode'];
37
+ }
33
38
}
34
39
35
40
.. code-block :: php-attributes
36
41
37
42
// src/Validator/ContainsAlphanumeric.php
38
43
namespace App\Validator;
39
44
45
+ use Symfony\Component\Validator\Attribute\HasNamedArguments;
40
46
use Symfony\Component\Validator\Constraint;
41
47
42
48
#[\Attribute]
43
49
class ContainsAlphanumeric extends Constraint
44
50
{
45
51
public $message = 'The string "{{ string }}" contains an illegal character: it can only contain letters or numbers.';
52
+
53
+ public string $mode;
54
+
55
+ #[HasNamedArguments]
56
+ public function __construct(string $mode, array $groups = null, mixed $payload = null)
57
+ {
58
+ parent::__construct([], $groups, $payload);
59
+
60
+ $this->mode = $mode;
61
+ }
46
62
}
47
63
48
64
Add ``@Annotation `` or ``#[\Attribute] `` to the constraint class if you want to
@@ -271,7 +287,7 @@ not to the property:
271
287
namespace App\Entity;
272
288
273
289
use App\Validator as AcmeAssert;
274
-
290
+
275
291
/**
276
292
* @AcmeAssert\ProtocolClass
277
293
*/
You can’t perform that action at this time.
0 commit comments