Hello. I am building a report class that has parameters passed in that determine which processes to implement upon the data.
In the example below, I would be able to do one of three things:
1. Send both the filter and sort variables, and it would apply both a filter and sort to the data.
2. Send one of the two variables, and it would apply either filter or sort to the data depending on which variable I sent.
3. Send neither variable, and neither process would be applied to the data.
I am using pipeIf, but, since this is my first time working with this function, I seem to be having trouble getting it to work. In my example code below, assume the variables $example_query, $example_filters, and $example_sort_by are filled with correctly formatted data for that process.
I believe it is something to do with $node because I am not aware of what to pass for that parameter and I cannot find anything in the documentation that directly explains what $node is.
$this->src('example_data')->query($example_query)
->pipeIf(!empty($example_filters),
function($node, $example_filters) {
return $node->pipe(new \koolreport\processes\Filter($example_filters));
})
->pipeIf(!empty($example_sort_by),
function($node, $example_sort_by) {
return $node->pipe(new \koolreport\processes\Sort($example_sort_by));
})
->pipe($this->dataStore('example_report'));
This is the error that I am getting back when this code is run (ExampleClass is a stand-in for the class that I have made that extends KoolReport):
Uncaught exception:
Too few arguments to function ExampleClass::{closure}(), 1 passed in filepath/koolreport/core/src/core/Node.php on line 103 and exactly 2 expected
Exception code: 0
File: filepath/ExampleReport.php
Line: 67