Skip to content

PHPLIB-293 Add support for a comment parameter to the aggregate command #432

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 3 commits into from
Nov 14, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions src/Operation/Aggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ public function __construct($databaseName, $collectionName, array $pipeline, arr
throw InvalidArgumentException::invalidType('"collation" option', $options['collation'], 'array or object');
}

if (isset($options['comment']) && ! is_string($options['comment'])) {
throw InvalidArgumentException::invalidType('"comment" option', $options['comment'], 'string');
}

if (isset($options['hint']) && ! is_string($options['hint']) && ! is_array($options['hint']) && ! is_object($options['hint'])) {
throw InvalidArgumentException::invalidType('"hint" option', $options['hint'], 'string or array or object');
}
Expand Down Expand Up @@ -276,6 +280,10 @@ private function createCommand(Server $server, $isCursorSupported)
$cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
}

if (isset($this->options['comment'])) {
$cmd['comment'] = $this->options['comment'];
}

Copy link
Member

Choose a reason for hiding this comment

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

Since comment and maxTimeMS are the same in the sense that we want to check if they're isset() and then copy them as-is into the $cmd document, I propose creating a foreach as we have in other command helpers:

foreach (['comment', 'maxTimeMS'] as $option) {
    if (isset($this->options[$option])) {
        $cmd[$option] = $this->options[$option];
    }
}

allowDiskUse is always set, so we can leave its earlier assignment as-is.

if (isset($this->options['collation'])) {
$cmd['collation'] = (object) $this->options['collation'];
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Operation/AggregateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public function provideInvalidConstructorOptions()
$options[][] = ['collation' => $value];
}

foreach ($this->getInvalidStringValues() as $value) {
$options[][] = ['comment' => $value];
}

foreach ($this->getInvalidHintValues() as $value) {
$options[][] = ['hint' => $value];
}
Expand Down