1 | <?php |
||
16 | class RowBuilder implements RowInterface |
||
17 | { |
||
18 | /** |
||
19 | * @var RowInterface[] |
||
20 | */ |
||
21 | private $mergedRows; |
||
22 | |||
23 | /** |
||
24 | * @var array<string, DataSourceInterface> |
||
25 | */ |
||
26 | private $datasourceAttributes; |
||
27 | |||
28 | /** |
||
29 | * @var array<string, RowInterface> |
||
30 | */ |
||
31 | private $rowAttributes; |
||
32 | |||
33 | /** |
||
34 | * @var array |
||
35 | */ |
||
36 | private $params; |
||
37 | |||
38 | /** |
||
39 | * RowBuilder constructor. |
||
40 | * @Important |
||
41 | * @param RowInterface[] $mergedRows |
||
42 | * @param array<string,DataSourceInterface> $datasourceAttributes |
||
43 | * @param array<string, RowInterface> $rowAttributes |
||
44 | * @param array $params |
||
45 | */ |
||
46 | public function __construct(array $mergedRows = array(), array $datasourceAttributes = array(), |
||
47 | array $rowAttributes = array(), array $params = array()) |
||
48 | { |
||
49 | $this->mergedRows = $mergedRows; |
||
50 | $this->datasourceAttributes = $datasourceAttributes; |
||
51 | $this->rowAttributes = $rowAttributes; |
||
52 | $this->params = $params; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @return array |
||
57 | */ |
||
58 | public function getRow() |
||
59 | { |
||
60 | $row = []; |
||
61 | foreach($this->mergedRows as $mergeRow) { |
||
62 | $mergeRow->setParameters($this->params); |
||
63 | if($currentRow = $mergeRow->getRow()) { |
||
64 | $row += $currentRow; |
||
65 | } |
||
66 | } |
||
67 | |||
68 | foreach($this->datasourceAttributes as $key => $dataSourceAttribute) { |
||
69 | /* @var $dataSourceAttribute DataSourceInterface */ |
||
70 | $dataSourceAttribute->setParameters($this->params); |
||
71 | if($currentData = $dataSourceAttribute->getData()) { |
||
72 | $row[$key] = $currentData; |
||
73 | } |
||
74 | } |
||
75 | |||
76 | foreach($this->rowAttributes as $key => $rowAttribute) { |
||
77 | /* @var $rowAttribute RowInterface */ |
||
78 | $rowAttribute->setParameters($this->params); |
||
79 | if($currentRow = $rowAttribute->getRow()) { |
||
80 | $row[$key] = $currentRow; |
||
81 | } |
||
82 | } |
||
83 | |||
84 | return $row; |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @param array $params |
||
89 | */ |
||
90 | public function setParameters(array $params) |
||
94 | } |