Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f61ca2a

Browse filesBrowse files
[Validator] Removal code-block php-annotations
1 parent 3a76000 commit f61ca2a
Copy full SHA for f61ca2a

File tree

1 file changed

+15
-42
lines changed
Filter options

1 file changed

+15
-42
lines changed

‎validation/custom_constraint.rst

Copy file name to clipboardExpand all lines: validation/custom_constraint.rst
+15-42Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -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

9063
Creating the Validator itself
9164
-----------------------------

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.