From 08b29d4000771b2a6ff863de40fdc2cf4a9da429 Mon Sep 17 00:00:00 2001 From: Oleksii Romanchenko Date: Sun, 5 Jan 2025 15:51:23 +0200 Subject: [PATCH] Add message parameter with exception if not Symfony Bridge ^7.1 used (#853) Co-authored-by: Oleksii Romanchenko --- src/Attribute/MapDocument.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Attribute/MapDocument.php b/src/Attribute/MapDocument.php index c757d7d7..a661d853 100644 --- a/src/Attribute/MapDocument.php +++ b/src/Attribute/MapDocument.php @@ -6,8 +6,12 @@ use Attribute; use Doctrine\Bundle\MongoDBBundle\ArgumentResolver\DocumentValueResolver; +use RuntimeException; use Symfony\Bridge\Doctrine\Attribute\MapEntity; +use function is_string; +use function property_exists; + #[Attribute(Attribute::TARGET_PARAMETER)] class MapDocument extends MapEntity { @@ -21,7 +25,20 @@ public function __construct( public array|string|null $id = null, bool $disabled = false, string $resolver = DocumentValueResolver::class, + public ?string $message = null, ) { - parent::__construct($class, $objectManager, $expr, $mapping, $exclude, $stripNull, $id, null, $disabled, $resolver); + if (! is_string($this->message)) { + parent::__construct($class, $objectManager, $expr, $mapping, $exclude, $stripNull, $id, null, $disabled, $resolver); + + return; + } + + if (! property_exists(MapEntity::class, 'message')) { + throw new RuntimeException( + 'The "message" options is not supported at "MapDocument". Please upgrade "symfony/doctrine-bridge" to "^7.1".', + ); + } + + parent::__construct($class, $objectManager, $expr, $mapping, $exclude, $stripNull, $id, null, $disabled, $resolver, $message); } }