Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Support custom not found message based on Doctrine Bridge MapEntity #853

Open
wants to merge 1 commit into
base: 5.1.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/Attribute/MapDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
Avariya marked this conversation as resolved.
Show resolved Hide resolved
}
}