1 | <?php |
||
12 | class MarkdownTable |
||
13 | { |
||
14 | /** |
||
15 | * @var array |
||
16 | */ |
||
17 | private $headers = []; |
||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | private $rows = []; |
||
22 | /** |
||
23 | * @var \Symfony\Component\Console\Output\OutputInterface |
||
24 | */ |
||
25 | private $output; |
||
26 | /** |
||
27 | * @var int[] |
||
28 | */ |
||
29 | private $columnWidths; |
||
30 | |||
31 | /** |
||
32 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
||
33 | */ |
||
34 | public function __construct(OutputInterface $output) |
||
38 | |||
39 | /** |
||
40 | * Set the column headers. |
||
41 | * |
||
42 | * @param array $headers |
||
43 | * @return $this |
||
44 | */ |
||
45 | public function setHeaders(array $headers) |
||
51 | |||
52 | /** |
||
53 | * Sets all rows, replacing any existing. |
||
54 | * |
||
55 | * @param array $rows |
||
56 | * @return MarkdownTable |
||
57 | */ |
||
58 | public function setRows(array $rows) |
||
63 | |||
64 | /** |
||
65 | * @param array $rows |
||
66 | * @return $this |
||
67 | */ |
||
68 | public function addRows(array $rows) |
||
75 | |||
76 | /** |
||
77 | * @param $row |
||
78 | * @return $this |
||
79 | */ |
||
80 | public function addRow($row) |
||
93 | |||
94 | /** |
||
95 | * @param int $index |
||
96 | * @param array $row |
||
97 | */ |
||
98 | public function setRow($index, array $row) |
||
102 | |||
103 | /** |
||
104 | * Renders table to output. |
||
105 | */ |
||
106 | public function render() |
||
116 | |||
117 | /** |
||
118 | * Renders a single row. |
||
119 | * |
||
120 | * @param array|TableSeparator $row |
||
121 | */ |
||
122 | private function renderRow($row) |
||
138 | |||
139 | /** |
||
140 | * Renders the row separator. In this case it should only be used as a header separator. |
||
141 | */ |
||
142 | private function renderRowSeparator() |
||
151 | |||
152 | /** |
||
153 | * Prepare for rendering |
||
154 | */ |
||
155 | private function prepare() |
||
163 | |||
164 | /** |
||
165 | * Extracts maximum column widths from a row. |
||
166 | * |
||
167 | * @param $row |
||
168 | */ |
||
169 | private function prepareColumnWidths($row) |
||
183 | } |
||
184 |