From 92a6267da4e030fe121752785f825e512ca3ac33 Mon Sep 17 00:00:00 2001 From: Mykola Martynov Date: Tue, 19 Sep 2023 11:17:02 +0300 Subject: [PATCH] Fix initialization of configurable options for the attribute --- validation/custom_constraint.rst | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/validation/custom_constraint.rst b/validation/custom_constraint.rst index d44346352fd..b3909515fa3 100644 --- a/validation/custom_constraint.rst +++ b/validation/custom_constraint.rst @@ -41,7 +41,16 @@ First you need to create a Constraint class and extend :class:`Symfony\\Componen class ContainsAlphanumeric extends Constraint { public $message = 'The string "{{ string }}" contains an illegal character: it can only contain letters or numbers.'; - public $mode = 'strict'; // If the constraint has configuration options, define them as public properties + public $mode = 'strict'; + + // all configurable options must be passed to the constructor + public function __construct(string $mode = null, string $message = null, array $groups = null, $payload = null) + { + parent::__construct([], $groups, $payload); + + $this->mode = $mode ?? $this->mode; + $this->message = $message ?? $this->message; + } } Add ``@Annotation`` or ``#[\Attribute]`` to the constraint class if you want to 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