Skip to content

Commit 92a6267

Browse files
authored
Fix initialization of configurable options for the attribute
1 parent 27dc68d commit 92a6267

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

validation/custom_constraint.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,16 @@ First you need to create a Constraint class and extend :class:`Symfony\\Componen
4141
class ContainsAlphanumeric extends Constraint
4242
{
4343
public $message = 'The string "{{ string }}" contains an illegal character: it can only contain letters or numbers.';
44-
public $mode = 'strict'; // If the constraint has configuration options, define them as public properties
44+
public $mode = 'strict';
45+
46+
// all configurable options must be passed to the constructor
47+
public function __construct(string $mode = null, string $message = null, array $groups = null, $payload = null)
48+
{
49+
parent::__construct([], $groups, $payload);
50+
51+
$this->mode = $mode ?? $this->mode;
52+
$this->message = $message ?? $this->message;
53+
}
4554
}
4655
4756
Add ``@Annotation`` or ``#[\Attribute]`` to the constraint class if you want to

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy