1 | <?php |
||
10 | class ArrayToTextTable |
||
11 | { |
||
12 | /** |
||
13 | * @var array |
||
14 | */ |
||
15 | private $data; |
||
16 | |||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | private $columnsList = []; |
||
21 | |||
22 | /** |
||
23 | * @var int |
||
24 | */ |
||
25 | private $maxLineLength = 40; |
||
26 | |||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | private $columnsLength = []; |
||
31 | |||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | private $result = []; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | private $charset = 'UTF-8'; |
||
41 | |||
42 | /** |
||
43 | * @var bool |
||
44 | */ |
||
45 | private $renderHeader = true; |
||
46 | |||
47 | public function __construct(array $data) |
||
51 | |||
52 | /** |
||
53 | * Set custom charset for columns values |
||
54 | * |
||
55 | * @param $charset |
||
56 | * |
||
57 | * @return \dekor\ArrayToTextTable |
||
58 | * @throws \Exception |
||
59 | */ |
||
60 | public function charset($charset) |
||
73 | |||
74 | /** |
||
75 | * Set mode to print no header in the table |
||
76 | * |
||
77 | * @return self |
||
78 | */ |
||
79 | public function noHeader() |
||
85 | |||
86 | /** |
||
87 | * @param int $length |
||
88 | * |
||
89 | * @return self |
||
90 | * @throws \Exception |
||
91 | */ |
||
92 | public function maxLineLength($length) |
||
102 | |||
103 | /** |
||
104 | * Build your ascii table and return the result |
||
105 | * |
||
106 | * @return string |
||
107 | */ |
||
108 | public function render() |
||
129 | |||
130 | /** |
||
131 | * Calculates list of columns in data |
||
132 | */ |
||
133 | protected function calcColumnsList() |
||
138 | |||
139 | /** |
||
140 | * Calculates length for string |
||
141 | * |
||
142 | * @param $str |
||
143 | * |
||
144 | * @return int |
||
145 | */ |
||
146 | protected function length($str) |
||
150 | |||
151 | /** |
||
152 | * Calculate maximum string length for each column |
||
153 | */ |
||
154 | private function calcColumnsLength() |
||
171 | |||
172 | /** |
||
173 | * Append a line separator to result |
||
174 | */ |
||
175 | private function lineSeparator() |
||
185 | |||
186 | /** |
||
187 | * @param $columnKey |
||
188 | * @param $value |
||
189 | * |
||
190 | * @return string |
||
191 | */ |
||
192 | private function column($columnKey, $value) |
||
196 | |||
197 | /** |
||
198 | * Render header part |
||
199 | * |
||
200 | * @return void |
||
201 | */ |
||
202 | private function renderHeader() |
||
220 | |||
221 | /** |
||
222 | * Render body section of table |
||
223 | * |
||
224 | * @return void |
||
225 | */ |
||
226 | private function renderBody() |
||
243 | } |
||
|
|||
244 |
This check marks files that end in a newline character, i.e. an empy line.