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

Init project #1

Merged
merged 7 commits into from
Oct 17, 2023
Merged

Init project #1

merged 7 commits into from
Oct 17, 2023

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Oct 16, 2023

.github/ISSUE_TEMPLATE/bug-report.md Outdated Show resolved Hide resolved
.github/ISSUE_TEMPLATE/bug-report.md Outdated Show resolved Hide resolved
.github/workflows/coding-standards.yml Show resolved Hide resolved

env:
PHP_VERSION: "8.2"
DRIVER_VERSION: "mongodb/mongo-php-driver@master"
Copy link
Member

Choose a reason for hiding this comment

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

Same question as in coding-standards.yml. Can this just use the most recent stable release?

.github/workflows/tests.yml Show resolved Hide resolved
README.md Show resolved Hide resolved
composer.json Show resolved Hide resolved
tests/Builder/PipelineTest.php Outdated Show resolved Hide resolved
composer.json Outdated Show resolved Hide resolved
tests/Builder/BuilderEncoderTest.php Show resolved Hide resolved
tests/Builder/BuilderEncoderTest.php Show resolved Hide resolved
tests/Builder/BuilderEncoderTest.php Show resolved Hide resolved
tests/Builder/BuilderEncoderTest.php Outdated Show resolved Hide resolved
tests/Builder/BuilderEncoderTest.php Outdated Show resolved Hide resolved
/**
* Defines how to encode a stage or an operator into BSON.
*
* @see BuilderEncoder
Copy link
Member

Choose a reason for hiding this comment

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

This exists in a different namespace: MongoDB\Builder. Do you need a use statement?

src/Builder/Type/CombinedFieldQuery.php Outdated Show resolved Hide resolved
src/Builder/Type/CombinedFieldQuery.php Outdated Show resolved Hide resolved
*/
public static function match(FieldQueryInterface|QueryInterface|Serializable|array|bool|float|int|stdClass|string|null ...$queries): MatchStage
{
// Override the generated method to allow variadic arguments
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason the generated method doesn't accept var args on its own?

Copy link
Member Author

@GromNaN GromNaN Oct 17, 2023

Choose a reason for hiding this comment

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

It's something I can work on later. Query can be passed to operators in all forms:

  • As single param: $elemMatch, $match. Variadic is great for them.
  • As a list of query: $and, $or, $nor, Variadic can't be used. But a variadic list of query(/* ... */)
  • With other params: $geoNear, $graphLookup. Variadic can't be used.
  • $not accept a single fieldQuery object without field name. So not variadic.

And I need to wrap the query objects in QueryObject and CombinedFieldQuery

src/Builder/Stage.php Outdated Show resolved Hide resolved
Remove issue template

Minor fixes
generator/composer.json Outdated Show resolved Hide resolved
Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

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

A few comments that may highlight things to fix, but happy to get this merged and revisit in more detail once we start adding test coverage for the operators.

'date' => [BSON\UTCDateTime::class],
'null' => ['null'],
'regex' => [BSON\Regex::class],
'javascript' => ['string', BSON\Javascript::class],
Copy link
Member

Choose a reason for hiding this comment

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

I wasn't aware that aggregation framework accepted a string alongside a Javascript object, but I assume this pertains to $function.

/**
* @param non-empty-string $function
*/
public function __construct(string $function)
Copy link
Member

Choose a reason for hiding this comment

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

$where accepts both a string and a Javascript object.

Copy link
Member Author

Choose a reason for hiding this comment

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

Type updated.

public function __construct(Document|Serializable|QueryInterface|stdClass|array $query)
{
if (is_array($query) || is_object($query)) {
$query = QueryObject::create(...$query);
Copy link
Member

Choose a reason for hiding this comment

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

Is it valid to use ... on an arbitrary object? Variable-length argument lists notes the ... operator is only applicable to arrays and Traversable objects.

Copy link
Member Author

Choose a reason for hiding this comment

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

This will be reworked when adding tests to this operators.

// Transform the result into an stdClass if a document is provided
if (! $outputWindow->operator instanceof WindowInterface && (is_array($result) || is_object($result))) {
if (! is_first_key_operator($result)) {
throw new LogicException(sprintf('Expected OutputWindow::$operator to be an operator. Got "%s"', array_key_first($result)));
Copy link
Member

Choose a reason for hiding this comment

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

array_key_first() requires an array parameter. This would fail if $result is an object (possible by the condition above).

{
$result = [];
/** @var mixed $val */
foreach (get_object_vars($value) as $val) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this fragile in that it depends on the declaration order of class properties? I suppose if the classes are all generated from YAML this won't be a concern.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we use the order in which properties are declared in the object to generate the array. Otherwise, we have to generate a specific encoding class for each operator with all the necessary metadata.

@GromNaN GromNaN merged commit cf5b119 into mongodb:0.1 Oct 17, 2023
@GromNaN GromNaN deleted the init branch October 17, 2023 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants