Skip to content

Commit 03e7e81

Browse files
committed
Merge branch '5.4' into 6.3
* 5.4: Fix initialization of configurable options for the attribute
2 parents 4e93a70 + 5b8f853 commit 03e7e81

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

validation/custom_constraint.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,16 @@ First you need to create a Constraint class and extend :class:`Symfony\\Componen
2424
class ContainsAlphanumeric extends Constraint
2525
{
2626
public string $message = 'The string "{{ string }}" contains an illegal character: it can only contain letters or numbers.';
27-
// If the constraint has configuration options, define them as public properties
2827
public string $mode = 'strict';
28+
29+
// all configurable options must be passed to the constructor
30+
public function __construct(string $mode = null, string $message = null, array $groups = null, $payload = null)
31+
{
32+
parent::__construct([], $groups, $payload);
33+
34+
$this->mode = $mode ?? $this->mode;
35+
$this->message = $message ?? $this->message;
36+
}
2937
}
3038
3139
Add ``#[\Attribute]`` to the constraint class if you want to

0 commit comments

Comments
 (0)