8000 Merge branch '6.3' into 6.4 · symfony/symfony-docs@7c239dc · GitHub
[go: up one dir, main page]

Skip to content

Commit 7c239dc

Browse files
committed
Merge branch '6.3' into 6.4
* 6.3: [Validator] Add missing types and return types
2 parents 43ace32 + 99aaa1e commit 7c239dc

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

reference/constraints/Callback.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Configuration
3939
class Author
4040
{
4141
#[Assert\Callback]
42-
public function validate(ExecutionContextInterface $context, $payload): void
42+
public function validate(ExecutionContextInterface $context, mixed $payload): void
4343
{
4444
// ...
4545
}
@@ -80,7 +80,7 @@ Configuration
8080
$metadata->addConstraint(new Assert\Callback('validate'));
8181
}
8282
83-
public function validate(ExecutionContextInterface $context, $payload): void
83+
public function validate(ExecutionContextInterface $context, mixed $payload): void
8484
{
8585
// ...
8686
}
@@ -101,7 +101,7 @@ field those errors should be attributed::
101101
// ...
102102
private string $firstName;
103103

104-
public function validate(ExecutionContextInterface $context, $payload)
104+
public function validate(ExecutionContextInterface $context, mixed $payload): void
105105
{
106106
// somehow you have an array of "fake names"
107107
$fakeNames = [/* ... */];
@@ -121,13 +121,13 @@ Static Callbacks
121121
You can also use the constraint with static methods. Since static methods don't
122122
have access to the object instance, they receive the object as the first argument::
123123

124-
public static function validate($object, ExecutionContextInterface $context, $payload)
124+
public static function validate(mixed $value, ExecutionContextInterface $context, mixed $payload): void
125125
{
126126
// somehow you have an array of "fake names"
127127
$fakeNames = [/* ... */];
128128

129129
// check if the name is actually a fake name
130-
if (in_array($object->getFirstName(), $fakeNames)) {
130+
if (in_array($value->getFirstName(), $fakeNames)) {
131131
$context->buildViolation('This name sounds totally fake!')
132132
->atPath('firstName')
133133
->addViolation()
@@ -149,7 +149,7 @@ Suppose your validation function is ``Acme\Validator::validate()``::
149149

150150
class Validator
151151
{
152-
public static function validate($object, ExecutionContextInterface $context, $payload)
152+
public static function validate(mixed $value, ExecutionContextInterface $context, mixed $payload): void
153153
{
154154
// ...
155155
}
@@ -206,7 +206,7 @@ You can then use the following configuration to invoke this validator:
206206
207207
class Author
208208
{
209-
public static function loadValidatorMetadata(ClassMetadata $metadata)
209+
public static function loadValidatorMetadata(ClassMetadata $metadata): void
210210
{
211211
$metadata->addConstraint(new Assert\Callback([
212212
Validator::class,
@@ -235,9 +235,9 @@ constructor of the Callback constraint::
235235

236236
class Author
237237
{
238-
public static function loadValidatorMetadata(ClassMetadata $metadata)
238+
public static function loadValidatorMetadata(ClassMetadata $metadata): void
239239
{
240-
$callback = function ($object, ExecutionContextInterface $context, $payload): void {
240+
$callback = function (mixed $value, ExecutionContextInterface $context, mixed $payload): void {
241241
// ...
242242
};
243243

reference/constraints/DisableAutoMapping.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
EDBE
@@ -76,7 +76,7 @@ metadata:
7676
{
7777
// ...
7878
79-
public static function loadValidatorMetadata(ClassMetadata $metadata)
79+
public static function loadValidatorMetadata(ClassMetadata $metadata): void
8080
{
8181
$metadata->addConstraint(new Assert\DisableAutoMapping());
8282
}

reference/constraints/EnableAutoMapping.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ metadata:
7676
{
7777
// ...
7878
79-
public static function loadValidatorMetadata(ClassMetadata $metadata)
79+
public static function loadValidatorMetadata(ClassMetadata $metadata): void
8080
{
8181
$metadata->addConstraint(new Assert\EnableAutoMapping());
8282
}

validation/custom_constraint.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ The validator class only has one required method ``validate()``::
8888

8989
class ContainsAlphanumericValidator extends ConstraintValidator
9090
{
91-
public function validate($value, Constraint $constraint): void
91+
public function validate(mixed $value, Constraint $constraint): void
9292
{
9393
if (!$constraint instanceof ContainsAlphanumeric) 1E0A {
9494
throw new UnexpectedTypeException($constraint, ContainsAlphanumeric::class);

0 commit comments

Comments
 (0)
0