1 | <?php |
||
11 | class FileBag |
||
12 | { |
||
13 | /** |
||
14 | * Initialize bag from $_FILES. |
||
15 | * |
||
16 | * @throws \InvalidArgumentException |
||
17 | */ |
||
18 | public function __construct() |
||
29 | |||
30 | /** |
||
31 | * Returns true if the FILE parameter is defined. |
||
32 | * |
||
33 | * @param string $key |
||
34 | * @return bool |
||
35 | */ |
||
36 | public function has(string $key): bool |
||
40 | |||
41 | /** |
||
42 | * An array of parameter names. |
||
43 | * |
||
44 | * @return array |
||
45 | */ |
||
46 | public function keys(): array |
||
50 | |||
51 | /** |
||
52 | * Get value by parameter name. |
||
53 | * |
||
54 | * @param string $key |
||
55 | * @param mixed|null $default The default value if parameter does not exist |
||
56 | * @return FileUpload|array|null |
||
57 | */ |
||
58 | public function fetch(string $key, $default = null) |
||
62 | |||
63 | /** |
||
64 | * Converts uploaded files to FileUpload instances. |
||
65 | * |
||
66 | * @param array|FileUpload $file A (multi-dimensional) array of uploaded file information |
||
67 | * @return array A (multi-dimensional) array of FileUpload instances |
||
68 | */ |
||
69 | private function convertFileInformation($file) |
||
93 | |||
94 | /** |
||
95 | * Fixes a malformed PHP $_FILES array. |
||
96 | * |
||
97 | * PHP has a bug that the format of the $_FILES array differs, depending on |
||
98 | * whether the uploaded file fields had normal field names or array-like |
||
99 | * field names ("normal" vs. "parent[child]"). |
||
100 | * |
||
101 | * This method fixes the array to look like the "normal" $_FILES array. |
||
102 | * |
||
103 | * It's safe to pass an already converted array, in which case this method |
||
104 | * just returns the original array unmodified. |
||
105 | * |
||
106 | * @param array $data |
||
107 | * @return array |
||
108 | */ |
||
109 | private function fixPhpFilesArray(array $data): array |
||
139 | |||
140 | private $bag; |
||
141 | } |