-
Notifications
You must be signed in to change notification settings - Fork 4
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
Init project #1
Conversation
d841e4b
to
75cbada
Compare
|
||
env: | ||
PHP_VERSION: "8.2" | ||
DRIVER_VERSION: "mongodb/mongo-php-driver@master" |
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.
Same question as in coding-standards.yml
. Can this just use the most recent stable release?
/** | ||
* Defines how to encode a stage or an operator into BSON. | ||
* | ||
* @see BuilderEncoder |
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.
This exists in a different namespace: MongoDB\Builder. Do you need a use
statement?
*/ | ||
public static function match(FieldQueryInterface|QueryInterface|Serializable|array|bool|float|int|stdClass|string|null ...$queries): MatchStage | ||
{ | ||
// Override the generated method to allow variadic arguments |
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.
Is there a reason the generated method doesn't accept var args on its own?
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.
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 ofquery(/* ... */)
- 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
Remove issue template Minor fixes
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.
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], |
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.
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) |
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.
$where accepts both a string and a Javascript object.
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.
Type updated.
public function __construct(Document|Serializable|QueryInterface|stdClass|array $query) | ||
{ | ||
if (is_array($query) || is_object($query)) { | ||
$query = QueryObject::create(...$query); |
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.
Is it valid to use ...
on an arbitrary object? Variable-length argument lists notes the ...
operator is only applicable to arrays and Traversable objects.
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.
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))); |
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.
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) { |
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.
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.
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.
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.
Import code from mongodb/mongo-php-library#1180