1 | <?php |
||
16 | class ExportHelper |
||
17 | { |
||
18 | /** |
||
19 | * Export an Array or ActiveQuery instance into a CSV formated string. |
||
20 | * |
||
21 | * @param array|ActiveQueryInterface $input The data to export into a csv |
||
22 | * @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. |
||
23 | * @param string $header Whether the column name should be set as header inside the csv or not. |
||
24 | * @return string The generated CSV as string. |
||
25 | */ |
||
26 | public static function csv($input, array $keys = [], $header = true) |
||
34 | |||
35 | /** |
||
36 | * Export an Array or ActiveQuery instance into a Excel formatted string. |
||
37 | * |
||
38 | * @param array|ActiveQueryInterface $input |
||
39 | * @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. |
||
40 | * @param bool $header |
||
41 | * @return mixed |
||
42 | * @throws Exception |
||
43 | * @since 1.0.4 |
||
44 | */ |
||
45 | public static function xlsx($input, array $keys = [], $header = true) |
||
56 | |||
57 | /** |
||
58 | * Check type of input and return correct array. |
||
59 | * |
||
60 | * @param array|object $input |
||
61 | * @return array |
||
62 | * @since 1.0.4 |
||
63 | */ |
||
64 | protected static function transformInput($input) |
||
72 | |||
73 | /** |
||
74 | * Generate content by rows. |
||
75 | * |
||
76 | * @param array $contentRows |
||
77 | * @param string$delimiter |
||
78 | * @param string $keys |
||
79 | * @param bool $generateHeader |
||
80 | * @return array |
||
81 | * @throws Exception |
||
82 | * @since 1.0.4 |
||
83 | */ |
||
84 | protected static function generateContentArray($contentRows, $keys, $generateHeader = true) |
||
131 | |||
132 | /** |
||
133 | * @param array $input |
||
134 | * @param $delimiter |
||
135 | * @return null|string |
||
136 | * @since 1.0.4 |
||
137 | */ |
||
138 | protected static function generateOutputString(array $input, $delimiter) |
||
147 | |||
148 | /** |
||
149 | * Generate a row by its items. |
||
150 | * |
||
151 | * @param array $row |
||
152 | * @param string $delimiter |
||
153 | * @param string $enclose |
||
154 | * @return string |
||
155 | * @since 1.0.4 |
||
156 | */ |
||
157 | protected static function generateRow(array $row, $delimiter, $enclose) |
||
172 | } |
||
173 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: