@@ -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
121121You can also use the constraint with static methods. Since static methods don't
122122have 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
0 commit comments