From a1e5c6bfbc3955361ce48c6180a6f5433daf74fb Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Tue, 14 Sep 2021 14:30:01 +0200 Subject: [PATCH] Allow to use constraints as PHP 8 attributes --- src/Validator/Constraints/IsTrue.php | 9 +++++++++ src/Validator/Constraints/IsTrueV3.php | 1 + 2 files changed, 10 insertions(+) diff --git a/src/Validator/Constraints/IsTrue.php b/src/Validator/Constraints/IsTrue.php index 8207d0a..1959437 100644 --- a/src/Validator/Constraints/IsTrue.php +++ b/src/Validator/Constraints/IsTrue.php @@ -8,12 +8,21 @@ * @Annotation * @Target("PROPERTY") */ +#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::IS_REPEATABLE)] class IsTrue extends Constraint { public $message = 'This value is not a valid captcha.'; public $invalidHostMessage = 'The captcha was not resolved on the right domain.'; + public function __construct(array $options = null, string $message = null, string invalidHostMessage = null, array $groups = null, $payload = null) + { + parent::__construct($options ?? [], $groups, $payload); + + $this->message = $message ?? $this->message; + $this->invalidHostMessage = $invalidHostMessage ?? $this->invalidHostMessage; + } + /** * {@inheritdoc} */ diff --git a/src/Validator/Constraints/IsTrueV3.php b/src/Validator/Constraints/IsTrueV3.php index a48e778..067073a 100755 --- a/src/Validator/Constraints/IsTrueV3.php +++ b/src/Validator/Constraints/IsTrueV3.php @@ -6,6 +6,7 @@ * @Annotation * @Target("PROPERTY") */ +#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::IS_REPEATABLE)] class IsTrueV3 extends IsTrue { /**