Skip to content

Commit 08b29d4

Browse files
AvariyaOleksii Romanchenko
andauthored
Add message parameter with exception if not Symfony Bridge ^7.1 used (#853)
Co-authored-by: Oleksii Romanchenko <[email protected]>
1 parent 0952d9a commit 08b29d4

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/Attribute/MapDocument.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66

77
use Attribute;
88
use Doctrine\Bundle\MongoDBBundle\ArgumentResolver\DocumentValueResolver;
9+
use RuntimeException;
910
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
1011

12+
use function is_string;
13+
use function property_exists;
14+
1115
#[Attribute(Attribute::TARGET_PARAMETER)]
1216
class MapDocument extends MapEntity
1317
{
@@ -21,7 +25,20 @@ public function __construct(
2125
public array|string|null $id = null,
2226
bool $disabled = false,
2327
string $resolver = DocumentValueResolver::class,
28+
public ?string $message = null,
2429
) {
25-
parent::__construct($class, $objectManager, $expr, $mapping, $exclude, $stripNull, $id, null, $disabled, $resolver);
30+
if (! is_string($this->message)) {
31+
parent::__construct($class, $objectManager, $expr, $mapping, $exclude, $stripNull, $id, null, $disabled, $resolver);
32+
33+
return;
34+
}
35+
36+
if (! property_exists(MapEntity::class, 'message')) {
37+
throw new RuntimeException(
38+
'The "message" options is not supported at "MapDocument". Please upgrade "symfony/doctrine-bridge" to "^7.1".',
39+
);
40+
}
41+
42+
parent::__construct($class, $objectManager, $expr, $mapping, $exclude, $stripNull, $id, null, $disabled, $resolver, $message);
2643
}
2744
}

0 commit comments

Comments
 (0)