-
Notifications
You must be signed in to change notification settings - Fork 232
Add DocumentValueResolver and MapDocument #774
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Doctrine\Bundle\MongoDBBundle\ArgumentResolver; | ||
|
|
||
| use Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolver; | ||
| use Symfony\Component\HttpFoundation\Request; | ||
| use Symfony\Component\HttpKernel\Controller\ValueResolverInterface; | ||
| use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata; | ||
|
|
||
| /** @internal */ | ||
| final class DocumentValueResolver implements ValueResolverInterface | ||
| { | ||
| public function __construct( | ||
| private EntityValueResolver $entityValueResolver, | ||
| ) { | ||
| } | ||
|
|
||
| public function resolve(Request $request, ArgumentMetadata $argument): array | ||
| { | ||
| return $this->entityValueResolver->resolve($request, $argument); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Doctrine\Bundle\MongoDBBundle\Attribute; | ||
|
|
||
| use Attribute; | ||
| use Doctrine\Bundle\MongoDBBundle\ArgumentResolver\DocumentValueResolver; | ||
| use Symfony\Bridge\Doctrine\Attribute\MapEntity; | ||
|
|
||
| #[Attribute(Attribute::TARGET_PARAMETER)] | ||
| class MapDocument extends MapEntity | ||
| { | ||
| public function __construct( | ||
| public ?string $class = null, | ||
| public ?string $objectManager = null, | ||
| public ?string $expr = null, | ||
| public ?array $mapping = null, | ||
| public ?array $exclude = null, | ||
| public ?bool $stripNull = null, | ||
| public array|string|null $id = null, | ||
| bool $disabled = false, | ||
| string $resolver = DocumentValueResolver::class, | ||
| ) { | ||
| parent::__construct($class, $objectManager, $expr, $mapping, $exclude, $stripNull, $id, null, $disabled, $resolver); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -208,13 +208,5 @@ | |
| <service id="doctrine_mongodb.odm.symfony.fixtures.loader" class="Doctrine\Bundle\MongoDBBundle\Loader\SymfonyFixturesLoader" public="false"> | ||
| <argument type="service" id="service_container" /> | ||
| </service> | ||
|
|
||
| <service id="doctrine_mongodb.odm.entity_value_resolver" class="Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolver"> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like a breaking change if someone is already using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmmm not sure about the BC break, these services were added in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We're fine changing logic given this argument :) |
||
| <argument type="service" id="doctrine_mongodb" /> | ||
| <argument type="service" id="doctrine_mongodb.odm.entity_value_resolver.expression_language" on-invalid="ignore" /> | ||
| <tag name="controller.argument_value_resolver" priority="110" /> | ||
| </service> | ||
|
|
||
| <service id="doctrine_mongodb.odm.entity_value_resolver.expression_language" class="Symfony\Component\ExpressionLanguage\ExpressionLanguage" /> | ||
| </services> | ||
| </container> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?xml version="1.0" ?> | ||
|
|
||
| <container xmlns="http://symfony.com/schema/dic/services" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
|
||
| <services> | ||
| <service id="doctrine_mongodb.odm.entity_value_resolver" class="Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolver"> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this and other services use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've changed the other ones, but not sure about this one since it's for the |
||
| <argument type="service" id="doctrine_mongodb" /> | ||
| <argument type="service" id="doctrine_mongodb.odm.document_value_resolver.expression_language" on-invalid="ignore" /> | ||
| </service> | ||
|
|
||
| <service id="doctrine_mongodb.odm.document_value_resolver.expression_language" class="Symfony\Component\ExpressionLanguage\ExpressionLanguage" /> | ||
|
|
||
| <service id="doctrine_mongodb.odm.document_value_resolver" class="Doctrine\Bundle\MongoDBBundle\ArgumentResolver\DocumentValueResolver"> | ||
| <argument type="service" id="doctrine_mongodb.odm.entity_value_resolver" /> | ||
| <tag name="Doctrine\Bundle\MongoDBBundle\ArgumentResolver\DocumentValueResolver" priority="110">controller.argument_value_resolver</tag> | ||
| </service> | ||
| </services> | ||
| </container> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why It's marked as
@internalif the original EntityValueResolver is not@internal?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @pepeh, in this case we provide the feature of fetching objects from the controller automatically, I decided to mark this class as
@internalsince to me it was an implementation detail, if we could use theEntityValueResolver, we could remove this class.Are you using this class directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@franmomu there is option to specify value resolver manually
#[ValueResolver(DocumentValueResolver::class)]https://symfony.com/doc/current/controller/value_resolver.html#managing-value-resolvers
But if class is
@internalIDE will show warning