Skip to content

Commit

Permalink
Debug the final pipelines built by the query builder.
Browse files Browse the repository at this point in the history
  • Loading branch information
TCB13 committed Sep 5, 2019
1 parent bbd0112 commit d99da28
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class QueryBuilder

private $customPipeline = [];

public static $pipelineDebug = false;
private static $pipelineLogs = [];

private $expectedMultipleResults = true;

protected static $mongoOperatorMap = [
Expand Down Expand Up @@ -131,7 +134,7 @@ public function findAll(): self
];
}

if (!empty($this->order) && (!is_object($this->customPipeline) || empty($this->customPipeline->pipeline))) {
if (!empty($this->order)) {
$pipeline[] = ["\$sort" => $this->order];
}

Expand Down Expand Up @@ -163,10 +166,24 @@ public function findAll(): self
throw new Exception("You must set a collection!");
}

if (self::$pipelineDebug) {
self::$pipelineLogs[] = $pipeline;
}

$this->result = $this->collection->aggregate($pipeline);
return $this;
}

public static function getPipelineLogs(): array
{
return self::$pipelineLogs;
}

public static function getLastPipelineLog(): array
{
return end(self::$pipelineLogs);
}

public function select($fields): self
{
$fields = is_array($fields) && count(func_get_args()) === 1 && is_int(key($fields)) ? $fields : func_get_args();
Expand Down

0 comments on commit d99da28

Please sign in to comment.