1 | <?php |
||
15 | class ExportHelper |
||
16 | { |
||
17 | /** |
||
18 | * Export an Array or QueryInterface instance into a CSV formated string. |
||
19 | * |
||
20 | * @param array|QueryInterface $input The data to export into a csv |
||
21 | * @param array $keys Defines which keys should be packed into the generated CSV. The defined keys does not change the sort behavior of the generated csv. |
||
22 | * @param string $header Whether the column name should be set as header inside the csv or not. |
||
23 | * @param array $options Options {@since 1.8.0} |
||
24 | * + `sort`: boolean, whether they row should be sorted by its keys, default is true. |
||
25 | * @return string The generated CSV as string. |
||
26 | */ |
||
27 | public static function csv($input, array $keys = [], $header = true, array $options = []) |
||
35 | |||
36 | /** |
||
37 | * Export an Array or QueryInterface instance into a Excel formatted string. |
||
38 | * |
||
39 | * @param array|QueryInterface $input |
||
40 | * @param array $keys Defines which keys should be packed into the generated xlsx. The defined keys does not change the sort behavior of the generated xls. |
||
41 | * @param bool $header |
||
42 | * @param array $options Options {@since 1.8.0} |
||
43 | * + `sort`: boolean, whether they row should be sorted by its keys, default is true. |
||
44 | * @return mixed |
||
45 | * @throws Exception |
||
46 | * @since 1.0.4 |
||
47 | */ |
||
48 | public static function xlsx($input, array $keys = [], $header = true, array $options = []) |
||
59 | |||
60 | /** |
||
61 | * Check type of input and return correct array. |
||
62 | * |
||
63 | * @param array|QueryInterface $input |
||
64 | * @return array |
||
65 | * @since 1.0.4 |
||
66 | */ |
||
67 | protected static function transformInput($input) |
||
75 | |||
76 | /** |
||
77 | * Generate content by rows. |
||
78 | * |
||
79 | * @param array $contentRows |
||
80 | * @param string $delimiter |
||
81 | * @param array $keys |
||
82 | * @param bool $generateHeader |
||
83 | * @param array $options Options {@since 1.8.0} |
||
84 | * + `sort`: boolean, whether they row should be sorted by its keys, default is true. |
||
85 | * @return array |
||
86 | * @throws Exception |
||
87 | * @since 1.0.4 |
||
88 | */ |
||
89 | protected static function generateContentArray($contentRows, array $keys, $generateHeader = true, $options = []) |
||
149 | |||
150 | /** |
||
151 | * Generate the output string with delimiters. |
||
152 | * |
||
153 | * @param array $input |
||
154 | * @param string $delimiter |
||
155 | * @return null|string |
||
156 | * @since 1.0.4 |
||
157 | */ |
||
158 | protected static function generateOutputString(array $input, $delimiter) |
||
167 | |||
168 | /** |
||
169 | * Generate a row by its items. |
||
170 | * |
||
171 | * @param array $row |
||
172 | * @param string $delimiter |
||
173 | * @param string $enclose |
||
174 | * @return string |
||
175 | * @since 1.0.4 |
||
176 | */ |
||
177 | protected static function generateRow(array $row, $delimiter, $enclose) |
||
196 | } |
||
197 |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.