Skip to content

Commit

Permalink
Add error message if mongodb/builder is not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Mar 14, 2024
1 parent 3428111 commit c46344f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
"issues": "https://www.mongodb.com/support",
"security": "https://www.mongodb.com/security"
},
"repositories": [
{ "type": "vcs", "url": "https://github.com/GromNaN/mongo-php-builder.git" }
],
"authors": [
{ "name": "Andreas Braun", "email": "andreas.braun@mongodb.com", "role": "Leader" },
{ "name": "Jérôme Tamarelle", "email": "jerome.tamarelle@mongodb.com", "role": "Maintainer" },
Expand All @@ -34,7 +31,7 @@
"mongodb/mongodb": "^1.15"
},
"require-dev": {
"mongodb/builder": "dev-laravel-fluent",
"mongodb/builder": "^0.2",
"phpunit/phpunit": "^10.3",
"orchestra/testbench": "^8.0|^9.0",
"mockery/mockery": "^1.4.4",
Expand Down
6 changes: 6 additions & 0 deletions src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use MongoDB\BSON\UTCDateTime;
use MongoDB\Builder\Accumulator;
use MongoDB\Builder\Expression\FieldPath;
use MongoDB\Builder\Stage\FluentFactoryTrait;
use MongoDB\Builder\Variable;
use MongoDB\Driver\Cursor;
use Override;
Expand Down Expand Up @@ -68,6 +69,7 @@
use function strlen;
use function strtolower;
use function substr;
use function trait_exists;
use function var_export;

class Builder extends BaseBuilder
Expand Down Expand Up @@ -284,6 +286,10 @@ public function dump(mixed ...$args)

private function getAggregationBuilder(): AggregationBuilder
{
if (! trait_exists(FluentFactoryTrait::class)) {
throw new BadMethodCallException('Aggregation builder requires package mongodb/builder 0.2+');
}

$agg = new AggregationBuilder([], $this->collection, $this->options);

$wheres = $this->compileWheres();
Expand Down

0 comments on commit c46344f

Please sign in to comment.