@@ -39,7 +39,7 @@ Configuration
39
39
class Author
40
40
{
41
41
#[Assert\Callback]
42
- public function validate(ExecutionContextInterface $context, $payload): void
42
+ public function validate(ExecutionContextInterface $context, mixed $payload): void
43
43
{
44
44
// ...
45
45
}
@@ -80,7 +80,7 @@ Configuration
80
80
$metadata->addConstraint(new Assert\Callback('validate'));
81
81
}
82
82
83
- public function validate(ExecutionContextInterface $context, $payload): void
83
+ public function validate(ExecutionContextInterface $context, mixed $payload): void
84
84
{
85
85
// ...
86
86
}
@@ -101,7 +101,7 @@ field those errors should be attributed::
101
101
// ...
102
102
private string $firstName;
103
103
104
- public function validate(ExecutionContextInterface $context, $payload)
104
+ public function validate(ExecutionContextInterface $context, mixed $payload): void
105
105
{
106
106
// somehow you have an array of "fake names"
107
107
$fakeNames = [/* ... */];
@@ -121,13 +121,13 @@ Static Callbacks
121
121
You can also use the constraint with static methods. Since static methods don't
122
122
have access to the object instance, they receive the object as the first argument::
123
123
124
- public static function validate($object , ExecutionContextInterface $context, $payload)
124
+ public static function validate(mixed $value , ExecutionContextInterface $context, mixed $payload): void
125
125
{
126
126
// somehow you have an array of "fake names"
127
127
$fakeNames = [/* ... */];
128
128
129
129
// check if the name is actually a fake name
130
- if (in_array($object ->getFirstName(), $fakeNames)) {
130
+ if (in_array($value ->getFirstName(), $fakeNames)) {
131
131
$context->buildViolation('This name sounds totally fake!')
132
132
->atPath('firstName')
133
133
->addViolation()
@@ -149,7 +149,7 @@ Suppose your validation function is ``Acme\Validator::validate()``::
149
149
150
150
class Validator
151
151
{
152
- public static function validate($object , ExecutionContextInterface $context, $payload)
152
+ public static function validate(mixed $value , ExecutionContextInterface $context, mixed $payload): void
153
153
{
154
154
// ...
155
155
}
@@ -206,7 +206,7 @@ You can then use the following configuration to invoke this validator:
206
206
207
207
class Author
208
208
{
209
- public static function loadValidatorMetadata(ClassMetadata $metadata)
209
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
210
210
{
211
211
$metadata->addConstraint(new Assert\Callback([
212
212
Validator::class,
@@ -235,9 +235,9 @@ constructor of the Callback constraint::
235
235
236
236
class Author
237
237
{
238
- public static function loadValidatorMetadata(ClassMetadata $metadata)
238
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
239
239
{
240
- $callback = function ($object , ExecutionContextInterface $context, $payload): void {
240
+ $callback = function (mixed $value , ExecutionContextInterface $context, mixed $payload): void {
241
241
// ...
242
242
};
243
243
0 commit comments