Skip to content

Commit 3533b55

Browse files
authored
Merge pull request #313 from norkunas/address-constraint-as-php8-attribute
Allow `Address` validation constraint as php8 attribute usage
2 parents b4152e5 + d404e2c commit 3533b55

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Validator/Constraint/Address.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*
2121
* @author Tomas Norkūnas <norkunas.tom@gmail.com>
2222
*/
23+
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
2324
class Address extends Constraint
2425
{
2526
public const INVALID_ADDRESS_ERROR = '2243aa07-2ea7-4eb7-962c-6a9586593f2c';
@@ -32,7 +33,14 @@ class Address extends Constraint
3233

3334
public $message = 'Address {{ address }} is not valid.';
3435

35-
public function validatedBy()
36+
public function __construct(array $options = null, string $message = null, array $groups = null, $payload = null)
37+
{
38+
parent::__construct($options, $groups, $payload);
39+
40+
$this->message = $message ?? $this->message;
41+
}
42+
43+
public function validatedBy(): string
3644
{
3745
return $this->service;
3846
}

0 commit comments

Comments
 (0)