File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,9 @@ class QueryBuilder
3636
3737 private $ customPipeline = [];
3838
39+ public static $ pipelineDebug = false ;
40+ private static $ pipelineLogs = [];
41+
3942 private $ expectedMultipleResults = true ;
4043
4144 protected static $ mongoOperatorMap = [
@@ -131,7 +134,7 @@ public function findAll(): self
131134 ];
132135 }
133136
134- if (!empty ($ this ->order ) && (! is_object ( $ this -> customPipeline ) || empty ( $ this -> customPipeline -> pipeline )) ) {
137+ if (!empty ($ this ->order )) {
135138 $ pipeline [] = ["\$sort " => $ this ->order ];
136139 }
137140
@@ -163,10 +166,24 @@ public function findAll(): self
163166 throw new Exception ("You must set a collection! " );
164167 }
165168
169+ if (self ::$ pipelineDebug ) {
170+ self ::$ pipelineLogs [] = $ pipeline ;
171+ }
172+
166173 $ this ->result = $ this ->collection ->aggregate ($ pipeline );
167174 return $ this ;
168175 }
169176
177+ public static function getPipelineLogs (): array
178+ {
179+ return self ::$ pipelineLogs ;
180+ }
181+
182+ public static function getLastPipelineLog (): array
183+ {
184+ return end (self ::$ pipelineLogs );
185+ }
186+
170187 public function select ($ fields ): self
171188 {
172189 $ fields = is_array ($ fields ) && count (func_get_args ()) === 1 && is_int (key ($ fields )) ? $ fields : func_get_args ();
You can’t perform that action at this time.
0 commit comments