Skip to content

Commit a00dddb

Browse files
committed
use named-arguments to configure validation constraint options
1 parent 171af72 commit a00dddb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+343
-427
lines changed

components/console/helpers/questionhelper.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,10 @@ invalid answer and will only be able to proceed if their input is valid.
480480
use Symfony\Component\Validator\Validation;
481481

482482
$question = new Question('Please enter the name of the bundle', 'AcmeDemoBundle');
483-
$validation = Validation::createCallable(new Regex([
484-
'pattern' => '/^[a-zA-Z]+Bundle$/',
485-
'message' => 'The name of the bundle should be suffixed with \'Bundle\'',
486-
]));
483+
$validation = Validation::createCallable(new Regex(
484+
pattern: '/^[a-zA-Z]+Bundle$/',
485+
message: 'The name of the bundle should be suffixed with \'Bundle\'',
486+
));
487487
$question->setValidator($validation);
488488

489489
Validating a Hidden Response

components/options_resolver.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ returns ``true`` for acceptable values and ``false`` for invalid values::
394394

395395
// ...
396396
$resolver->setAllowedValues('transport', Validation::createIsValidCallable(
397-
new Length(['min' => 10 ])
397+
new Length(min: 10)
398398
));
399399

400400
In sub-classes, you can use :method:`Symfony\\Component\\OptionsResolver\\OptionsResolver::addAllowedValues`

components/validator.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ characters long::
3636

3737
$validator = Validation::createValidator();
3838
$violations = $validator->validate('Bernhard', [
39-
new Length(['min' => 10]),
39+
new Length(min: 10),
4040
new NotBlank(),
4141
]);
4242

components/validator/metadata.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ the ``Author`` class has at least 3 characters::
2424
$metadata->addPropertyConstraint('firstName', new Assert\NotBlank());
2525
$metadata->addPropertyConstraint(
2626
'firstName',
27-
new Assert\Length(["min" => 3])
27+
new Assert\Length(min: 3)
2828
);
2929
}
3030
}
@@ -55,9 +55,9 @@ Then, add the Validator component configuration to the class::
5555
{
5656
public static function loadValidatorMetadata(ClassMetadata $metadata): void
5757
{
58-
$metadata->addGetterConstraint('passwordSafe', new Assert\IsTrue([
59-
'message' => 'The password cannot match your first name',
60-
]));
58+
$metadata->addGetterConstraint('passwordSafe', new Assert\IsTrue(
59+
message: 'The password cannot match your first name',
60+
));
6161
}
6262
}
6363

components/validator/resources.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ In this example, the validation metadata is retrieved executing the
4242
public static function loadValidatorMetadata(ClassMetadata $metadata): void
4343
{
4444
$metadata->addPropertyConstraint('name', new Assert\NotBlank());
45-
$metadata->addPropertyConstraint('name', new Assert\Length([
46-
'min' => 5,
47-
'max' => 20,
48-
]));
45+
$metadata->addPropertyConstraint('name', new Assert\Length(
46+
min: 5,
47+
max: 20,
48+
));
4949
}
5050
}
5151

controller/upload_file.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ so Symfony doesn't try to get/set its value from the related entity::
7575
// unmapped fields can't define their validation using attributes
7676
// in the associated entity, so you can use the PHP constraint classes
7777
'constraints' => [
78-
new File([
79-
'maxSize' => '1024k',
80-
'mimeTypes' => [
78+
new File(
79+
maxSize: '1024k',
80+
mimeTypes: [
8181
'application/pdf',
8282
'application/x-pdf',
8383
],
84-
'mimeTypesMessage' => 'Please upload a valid PDF document',
85-
])
84+
mimeTypesMessage: 'Please upload a valid PDF document',
85+
)
8686
],
8787
])
8888
// ...

form/without_class.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ but here's a short example::
9696
{
9797
$builder
9898
->add('firstName', TextType::class, [
99-
'constraints' => new Length(['min' => 3]),
99+
'constraints' => new Length(min: 3),
100100
])
101101
->add('lastName', TextType::class, [
102102
'constraints' => [
103103
new NotBlank(),
104-
new Length(['min' => 3]),
104+
new Length(min: 3),
105105
],
106106
])
107107
;
@@ -153,10 +153,10 @@ This can be done by setting the ``constraints`` option in the
153153
$resolver->setDefaults([
154154
'data_class' => null,
155155
'constraints' => new Collection([
156-
'firstName' => new Length(['min' => 3]),
156+
'firstName' => new Length(min: 3),
157157
'lastName' => [
158158
new NotBlank(),
159-
new Length(['min' => 3]),
159+
new Length(min: 3),
160160
],
161161
]),
162162
]);

reference/constraints/All.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ entry in that array:
7979
{
8080
public static function loadValidatorMetadata(ClassMetadata $metadata): void
8181
{
82-
$metadata->addPropertyConstraint('favoriteColors', new Assert\All([
83-
'constraints' => [
82+
$metadata->addPropertyConstraint('favoriteColors', new Assert\All(
83+
constraints: [
8484
new Assert\NotBlank(),
85-
new Assert\Length(['min' => 5]),
85+
new Assert\Length(min: 5),
8686
],
87-
]));
87+
));
8888
}
8989
}
9090
@@ -97,7 +97,7 @@ Options
9797
``constraints``
9898
~~~~~~~~~~~~~~~
9999

100-
**type**: ``array`` [:ref:`default option <validation-default-option>`]
100+
**type**: ``array``
101101

102102
This required option is the array of validation constraints that you want
103103
to apply to each element of the underlying array.

reference/constraints/AtLeastOneOf.rst

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,23 +115,23 @@ The following constraints ensure that:
115115
{
116116
public static function loadValidatorMetadata(ClassMetadata $metadata): void
117117
{
118-
$metadata->addPropertyConstraint('password', new Assert\AtLeastOneOf([
119-
'constraints' => [
120-
new Assert\Regex(['pattern' => '/#/']),
121-
new Assert\Length(['min' => 10]),
118+
$metadata->addPropertyConstraint('password', new Assert\AtLeastOneOf(
119+
constraints: [
120+
new Assert\Regex(pattern: '/#/'),
121+
new Assert\Length(min: 10),
122122
],
123-
]));
123+
));
124124
125-
$metadata->addPropertyConstraint('grades', new Assert\AtLeastOneOf([
126-
'constraints' => [
127-
new Assert\Count(['min' => 3]),
128-
new Assert\All([
129-
'constraints' => [
125+
$metadata->addPropertyConstraint('grades', new Assert\AtLeastOneOf(
126+
constraints: [
127+
new Assert\Count(min: 3),
128+
new Assert\All(
129+
constraints: [
130130
new Assert\GreaterThanOrEqual(5),
131131
],
132-
]),
132+
),
133133
],
134-
]));
134+
));
135135
}
136136
}
137137
@@ -141,7 +141,7 @@ Options
141141
constraints
142142
~~~~~~~~~~~
143143

144-
**type**: ``array`` [:ref:`default option <validation-default-option>`]
144+
**type**: ``array``
145145

146146
This required option is the array of validation constraints from which at least one of
147147
has to be satisfied in order for the validation to succeed.

reference/constraints/Callback.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ Options
259259
``callback``
260260
~~~~~~~~~~~~
261261

262-
**type**: ``string``, ``array`` or ``Closure`` [:ref:`default option <validation-default-option>`]
262+
**type**: ``string``, ``array`` or ``Closure``
263263

264264
The callback option accepts three different formats for specifying the
265265
callback method:

0 commit comments

Comments
 (0)