Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 10 |
Builder | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 10 |
createView | |
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 10 |
1 | <?php |
2 | |
3 | |
4 | namespace Qmp\Laravel\MongoLow\Schema; |
5 | |
6 | use Illuminate\Support\Collection; |
7 | use Jenssegers\Mongodb\Schema\Builder as JenssegersSchemaBuilder; |
8 | use Qmp\Laravel\MongoLow\MongoPipeline; |
9 | |
10 | class Builder extends JenssegersSchemaBuilder |
11 | { |
12 | /** |
13 | * Create a new view inside mongo |
14 | * |
15 | * @param string $name |
16 | * @param string $on |
17 | * @param mixed $pipeline |
18 | * @return void |
19 | */ |
20 | public function createView(string $name, string $on, $pipeline): void |
21 | { |
22 | $db = $this->connection->getMongoDB(); |
23 | |
24 | if ($pipeline instanceof MongoPipeline || $pipeline instanceof Collection) { |
25 | $pipeline = $pipeline->toArray(); |
26 | } else if (is_string($pipeline) && (substr($pipeline, 0, 1) === "{" || substr($pipeline, 0, 1) === "[")) { |
27 | $pipeline = json_decode($pipeline, true); |
28 | } |
29 | |
30 | $db->command([ |
31 | 'create' => $name, |
32 | 'viewOn' => $on, |
33 | 'pipeline' => $pipeline |
34 | ]); |
35 | } |
36 | } |