1 | <?php |
||
17 | class UploadedFilesFactory |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * Creates the uploaded file objects within a normalized files tree |
||
22 | * |
||
23 | * @return array|UploadedFile[] |
||
24 | */ |
||
25 | public static function createFiles() |
||
35 | |||
36 | /** |
||
37 | * Helper function to recursively create UploadedFile objects |
||
38 | * |
||
39 | * @param array $data |
||
40 | * |
||
41 | * @return array|UploadedFile |
||
42 | */ |
||
43 | private function createUploadedFile($data) |
||
55 | |||
56 | /** |
||
57 | * Fixes the $_FILES array structure |
||
58 | * |
||
59 | * For each subtree in the file tree that's more than one item deep: |
||
60 | * For each leaf of the subtree: |
||
61 | * $leaf[a][b][c] ... [y][z] -> $result[z][a][b][c] ... [y] |
||
62 | * |
||
63 | * |
||
64 | * @see: https://stackoverflow.com/a/24397828/1271488 |
||
65 | * |
||
66 | * @param array $files |
||
67 | * @return array |
||
68 | */ |
||
69 | private function saneFilesArray(array $files) |
||
89 | |||
90 | /** |
||
91 | * Move the innermost key to the outer spot |
||
92 | * |
||
93 | * @param array $result |
||
94 | * @param array $keys |
||
95 | * @param mixed $value |
||
96 | */ |
||
97 | private function filesFlip(&$result, $keys, $value) |
||
120 | |||
121 | /** |
||
122 | * Recursively merge provided arrays |
||
123 | * |
||
124 | * @param array|string $array1 |
||
125 | * @param array|string $array2 |
||
126 | * |
||
127 | * @return array |
||
128 | */ |
||
129 | private function arrayMergeRecursive($array1, $array2) |
||
138 | } |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: