Skip to content

Commit f38f5c7

Browse files
committed
Remove Query\Builder::__constructor overload
1 parent 49ec43c commit f38f5c7

File tree

6 files changed

+16
-21
lines changed

6 files changed

+16
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file.
1616
- Remove `Query\Builder::whereAll($column, $values)`. Use `Query\Builder::where($column, 'all', $values)` instead. [#16](https://github.com/GromNaN/laravel-mongodb-private/pull/16) by [@GromNaN](https://github.com/GromNaN).
1717
- Fix validation of unique values when the validated value is found as part of an existing value. [#21](https://github.com/GromNaN/laravel-mongodb-private/pull/21) by [@GromNaN](https://github.com/GromNaN).
1818
- Support `%` and `_` in `like` expression [#17](https://github.com/GromNaN/laravel-mongodb-private/pull/17) by [@GromNaN](https://github.com/GromNaN).
19+
- Change signature of `Query\Builder::__constructor` to match the parent class [#26](https://github.com/GromNaN/laravel-mongodb-private/pull/26) by [@GromNaN](https://github.com/GromNaN).
1920

2021
## [3.9.2] - 2022-09-01
2122

src/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function __construct(array $config)
7474
*/
7575
public function collection($collection)
7676
{
77-
$query = new Query\Builder($this, $this->getPostProcessor());
77+
$query = new Query\Builder($this, $this->getQueryGrammar(), $this->getPostProcessor());
7878

7979
return $query->from($collection);
8080
}

src/Eloquent/Builder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ public function chunkById($count, callable $callback, $column = '_id', $alias =
164164
/**
165165
* @inheritdoc
166166
*/
167-
public function raw($expression = null)
167+
public function raw($value = null)
168168
{
169169
// Get raw results from the query builder.
170-
$results = $this->query->raw($expression);
170+
$results = $this->query->raw($value);
171171

172172
// Convert MongoCursor results to a collection of models.
173173
if ($results instanceof Cursor) {

src/Eloquent/Model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ protected function newBaseQueryBuilder()
433433
{
434434
$connection = $this->getConnection();
435435

436-
return new QueryBuilder($connection, $connection->getPostProcessor());
436+
return new QueryBuilder($connection, $connection->getQueryGrammar(), $connection->getPostProcessor());
437437
}
438438

439439
/**

src/Query/Builder.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,6 @@ class Builder extends BaseBuilder
134134
'uniquedocs' => 'uniqueDocs',
135135
];
136136

137-
/**
138-
* @inheritdoc
139-
*/
140-
public function __construct(Connection $connection, Processor $processor)
141-
{
142-
$this->grammar = new Grammar;
143-
$this->connection = $connection;
144-
$this->processor = $processor;
145-
}
146-
147137
/**
148138
* Set the projections.
149139
*
@@ -758,16 +748,16 @@ public function lists($column, $key = null)
758748
/**
759749
* @inheritdoc
760750
*/
761-
public function raw($expression = null)
751+
public function raw($value = null)
762752
{
763753
// Execute the closure on the mongodb collection
764-
if ($expression instanceof Closure) {
765-
return call_user_func($expression, $this->collection);
754+
if ($value instanceof Closure) {
755+
return call_user_func($value, $this->collection);
766756
}
767757

768758
// Create an expression for the given value
769-
if ($expression !== null) {
770-
return new Expression($expression);
759+
if ($value !== null) {
760+
return new Expression($value);
771761
}
772762

773763
// Quick access to the mongodb collection
@@ -853,10 +843,12 @@ public function drop($columns)
853843

854844
/**
855845
* @inheritdoc
846+
*
847+
* @return static
856848
*/
857849
public function newQuery()
858850
{
859-
return new self($this->connection, $this->processor);
851+
return new self($this->connection, $this->grammar, $this->processor);
860852
}
861853

862854
/**

tests/Query/BuilderTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Tests\Database\DatabaseQueryBuilderTest;
1010
use Jenssegers\Mongodb\Connection;
1111
use Jenssegers\Mongodb\Query\Builder;
12+
use Jenssegers\Mongodb\Query\Grammar;
1213
use Jenssegers\Mongodb\Query\Processor;
1314
use Mockery as m;
1415
use MongoDB\BSON\Regex;
@@ -838,7 +839,8 @@ private static function getBuilder(): Builder
838839
$connection = m::mock(Connection::class);
839840
$processor = m::mock(Processor::class);
840841
$connection->shouldReceive('getSession')->andReturn(null);
842+
$connection->shouldReceive('getQueryGrammar')->andReturn(new Grammar());
841843

842-
return new Builder($connection, $processor);
844+
return new Builder($connection, null, $processor);
843845
}
844846
}

0 commit comments

Comments
 (0)