Skip to content

Allow specifying options in AutowireDatabase and AutowireCollection #14

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

Merged
merged 6 commits into from
Dec 9, 2023

Conversation

alcaeus
Copy link
Collaborator

@alcaeus alcaeus commented Dec 9, 2023

This PR removes the options parameter from AutowireCollection and AutowireDatabase, and instead adds arguments for all options supported by the selectCollection and selectDatabase methods. When passing a string value, it is treated as a service reference to be injected. The only exception to this is the typeMap parameter, where a string is treated as a parameter name since it will resolve to an array value, not a service.

@alcaeus alcaeus added the enhancement New feature or request label Dec 9, 2023
@alcaeus alcaeus added this to the 0.2 milestone Dec 9, 2023
@alcaeus alcaeus requested a review from GromNaN December 9, 2023 12:00
@alcaeus alcaeus self-assigned this Dec 9, 2023
@@ -44,6 +46,7 @@ public function __construct(
private readonly ?string $collection = null,
private readonly ?string $database = null,
?string $client = null,
private readonly string|DocumentCodec|null $codec = null,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you pass a DocumentCodec instance?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added an example, but it's rather straightforward:

use MongoDB\Bundle\Attribute\AutowireCollection;
use MongoDB\Collection;
use MongoDB\Driver\ReadPreference;

class MyService
{
    public function __construct(
        #[AutowireCollection(codec: Codec::class, readPreference: new ReadPreference('secondary'))]
        private Collection $myCollection,
    ) {}
}

@alcaeus alcaeus changed the title Introduce codec option to AutowireCollection Allow specifying options in AutowireDatabase and AutowireCollection Dec 9, 2023
@alcaeus alcaeus requested a review from GromNaN December 9, 2023 13:45
@alcaeus alcaeus merged commit 74668e0 into mongodb-labs:0.2 Dec 9, 2023
@alcaeus alcaeus deleted the codec-option branch December 9, 2023 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants