I have a use case where I display variables in a PDF file. But to get there is not simple, but I could do something like this:
/*
* takes product model number, retrieves, processes, formats values
* returns $variables, ready to plug-in to view with no further processing
*/
$variables = $this->repository->getVariables($model);
/*
* View runs PDF Library code and displays variables and their values in a table
*/
$this->sendToView($variables);
Way 1 - Have Repository Do all the work to transform variables
inside getVariables
I would do these:
- read raw data from database tables (stored expressions)
- run data through expression engine (it evaluates the expressions)
- format resulting numeric data (i.e. round to 2 decimal points)
- add denominations (i.e. mm or inches)
- adorn data (put engineering tolerances, or extra wording around variables)
- re-group data for consumption by the PDF API engine (the view)
All the work will be done in getVariables
and sendToView
will then directly plug the variables as PDF API directs, no transformation needed
Way 2 - Use repository to get raw data only
Opposite extreme is have getVariables
do #1 only and have separate classes do their own things .. I could end up with
$expressions = $this->repository->getVariables($model);
$solveExpressions = $this->expressionEngine->process($expressions);
$formattedVars = $this->formatter->format($solvedExpressions);
$denominatedData = $this->denom->addMarkers($formattedVars);
$adornedData = $this->adorner->adorn($denominatedData);
$viewReadyData = $this->viewPreparer->prep($adornedData);
$this->sendToView($viewReadyData);
Or I could mix and match the above and stuff the methods into various classes..
My question
How much of the data transformation, formatting, regrouping, polishing, preparation, etc goes into the repository layer?
(That will help me determine what of the data manipulation will need to be done outside of repository layer, and maybe even what of the data manipulation is to be done in the view layer - i.e. simple regrouping of data for easier way to plug into a table)
P.S. What am I trying to do (data manipulation)
Without focusing on code, in the context of the question, what I am doing is this -- starting with expressions stored in database:
a = 5
b = a + 3
Then I end up with solved expressions:
a = 5
b = 8
Then I do a series or formatting and adorning like so:
8 => 8.00 => 8.00mm => 8.00mm +/-0.01
where during the above is stays in a form similar to
array(
'a' => '5.00mm +/-0.01',
'b' => '8.00mm +/-0.01'
);
For the view I transform that into
array(
0 => array(
'description' => 'a',
'value' => '5.00mm +/-0.01'
),
1 => array(
'description' => 'b',
'value' => '8.00mm +/-0.01'
)
);
And I wish to write the above into modern OOP code.