@@ -18,139 +18,139 @@ |
||
18 | 18 | */ |
19 | 19 | class FileSubmission implements FileSubmissionInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * @var string original name on the client machine |
|
23 | - */ |
|
24 | - protected $name; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var string mime type |
|
28 | - */ |
|
29 | - protected $type; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var string file extension |
|
33 | - */ |
|
34 | - protected $extension; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var int in bytes |
|
38 | - */ |
|
39 | - protected $size; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var string local filepath to the temporary file |
|
43 | - */ |
|
44 | - protected $tmp_file; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var int one of UPLOAD_ERR_OK, UPLOAD_ERR_NO_FILE, UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE or other values |
|
48 | - * although those aren't expected. |
|
49 | - */ |
|
50 | - protected $error_code; |
|
51 | - |
|
52 | - public function __construct($name, $tmp_file, $size, $error_code = null) |
|
53 | - { |
|
54 | - $this->name = basename($name); |
|
55 | - $this->tmp_file = $tmp_file; |
|
56 | - $this->size = (int) $size; |
|
57 | - $this->error_code = (int) $error_code; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * @return string |
|
62 | - */ |
|
63 | - public function getName() |
|
64 | - { |
|
65 | - return $this->name; |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Gets the file's mime type |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - public function getType() |
|
73 | - { |
|
74 | - if (!$this->type) { |
|
75 | - $this->type = $this->determineType(); |
|
76 | - } |
|
77 | - return $this->type; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @since $VID:$ |
|
82 | - * @return string |
|
83 | - */ |
|
84 | - protected function determineType() |
|
85 | - { |
|
86 | - if (!$this->getTmpFile()) { |
|
87 | - return ''; |
|
88 | - } |
|
89 | - $finfo = new finfo(FILEINFO_MIME_TYPE); |
|
90 | - return $finfo->file($this->getTmpFile()); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Gets the file's extension. |
|
95 | - * @since $VID:$ |
|
96 | - * @return string |
|
97 | - */ |
|
98 | - public function getExtension() |
|
99 | - { |
|
100 | - if (!$this->extension) { |
|
101 | - $this->extension = $this->determineExtension(); |
|
102 | - } |
|
103 | - return $this->extension; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Determine's the file's extension given the temporary file. |
|
108 | - * @since $VID:$ |
|
109 | - * @return string |
|
110 | - */ |
|
111 | - protected function determineExtension() |
|
112 | - { |
|
113 | - if (!$this->getTmpFile()) { |
|
114 | - return ''; |
|
115 | - } |
|
116 | - return pathinfo($this->getTmpFile(), PATHINFO_EXTENSION); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Gets the size of the file |
|
121 | - * @return int |
|
122 | - */ |
|
123 | - public function getSize() |
|
124 | - { |
|
125 | - return $this->size; |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Gets the path to the temporary file which was uploaded. |
|
130 | - * @return string |
|
131 | - */ |
|
132 | - public function getTmpFile() |
|
133 | - { |
|
134 | - return $this->tmp_file; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * @since $VID:$ |
|
139 | - * @return string |
|
140 | - */ |
|
141 | - public function __toString() |
|
142 | - { |
|
143 | - return $this->getTmpFile(); |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Gets the error code PHP reported for the file upload. |
|
148 | - * @return string |
|
149 | - */ |
|
150 | - public function getErrorCode() |
|
151 | - { |
|
152 | - return $this->error_code; |
|
153 | - } |
|
21 | + /** |
|
22 | + * @var string original name on the client machine |
|
23 | + */ |
|
24 | + protected $name; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var string mime type |
|
28 | + */ |
|
29 | + protected $type; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var string file extension |
|
33 | + */ |
|
34 | + protected $extension; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var int in bytes |
|
38 | + */ |
|
39 | + protected $size; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var string local filepath to the temporary file |
|
43 | + */ |
|
44 | + protected $tmp_file; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var int one of UPLOAD_ERR_OK, UPLOAD_ERR_NO_FILE, UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE or other values |
|
48 | + * although those aren't expected. |
|
49 | + */ |
|
50 | + protected $error_code; |
|
51 | + |
|
52 | + public function __construct($name, $tmp_file, $size, $error_code = null) |
|
53 | + { |
|
54 | + $this->name = basename($name); |
|
55 | + $this->tmp_file = $tmp_file; |
|
56 | + $this->size = (int) $size; |
|
57 | + $this->error_code = (int) $error_code; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * @return string |
|
62 | + */ |
|
63 | + public function getName() |
|
64 | + { |
|
65 | + return $this->name; |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Gets the file's mime type |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + public function getType() |
|
73 | + { |
|
74 | + if (!$this->type) { |
|
75 | + $this->type = $this->determineType(); |
|
76 | + } |
|
77 | + return $this->type; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @since $VID:$ |
|
82 | + * @return string |
|
83 | + */ |
|
84 | + protected function determineType() |
|
85 | + { |
|
86 | + if (!$this->getTmpFile()) { |
|
87 | + return ''; |
|
88 | + } |
|
89 | + $finfo = new finfo(FILEINFO_MIME_TYPE); |
|
90 | + return $finfo->file($this->getTmpFile()); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Gets the file's extension. |
|
95 | + * @since $VID:$ |
|
96 | + * @return string |
|
97 | + */ |
|
98 | + public function getExtension() |
|
99 | + { |
|
100 | + if (!$this->extension) { |
|
101 | + $this->extension = $this->determineExtension(); |
|
102 | + } |
|
103 | + return $this->extension; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Determine's the file's extension given the temporary file. |
|
108 | + * @since $VID:$ |
|
109 | + * @return string |
|
110 | + */ |
|
111 | + protected function determineExtension() |
|
112 | + { |
|
113 | + if (!$this->getTmpFile()) { |
|
114 | + return ''; |
|
115 | + } |
|
116 | + return pathinfo($this->getTmpFile(), PATHINFO_EXTENSION); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Gets the size of the file |
|
121 | + * @return int |
|
122 | + */ |
|
123 | + public function getSize() |
|
124 | + { |
|
125 | + return $this->size; |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Gets the path to the temporary file which was uploaded. |
|
130 | + * @return string |
|
131 | + */ |
|
132 | + public function getTmpFile() |
|
133 | + { |
|
134 | + return $this->tmp_file; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * @since $VID:$ |
|
139 | + * @return string |
|
140 | + */ |
|
141 | + public function __toString() |
|
142 | + { |
|
143 | + return $this->getTmpFile(); |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Gets the error code PHP reported for the file upload. |
|
148 | + * @return string |
|
149 | + */ |
|
150 | + public function getErrorCode() |
|
151 | + { |
|
152 | + return $this->error_code; |
|
153 | + } |
|
154 | 154 | } |
155 | 155 | // End of file FileSubmission.php |
156 | 156 | // Location: EventEspresso\core\services\request\files/FileSubmission.php |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function getType() |
73 | 73 | { |
74 | - if (!$this->type) { |
|
74 | + if ( ! $this->type) { |
|
75 | 75 | $this->type = $this->determineType(); |
76 | 76 | } |
77 | 77 | return $this->type; |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | */ |
84 | 84 | protected function determineType() |
85 | 85 | { |
86 | - if (!$this->getTmpFile()) { |
|
86 | + if ( ! $this->getTmpFile()) { |
|
87 | 87 | return ''; |
88 | 88 | } |
89 | 89 | $finfo = new finfo(FILEINFO_MIME_TYPE); |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function getExtension() |
99 | 99 | { |
100 | - if (!$this->extension) { |
|
100 | + if ( ! $this->extension) { |
|
101 | 101 | $this->extension = $this->determineExtension(); |
102 | 102 | } |
103 | 103 | return $this->extension; |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | */ |
111 | 111 | protected function determineExtension() |
112 | 112 | { |
113 | - if (!$this->getTmpFile()) { |
|
113 | + if ( ! $this->getTmpFile()) { |
|
114 | 114 | return ''; |
115 | 115 | } |
116 | 116 | return pathinfo($this->getTmpFile(), PATHINFO_EXTENSION); |
@@ -42,194 +42,194 @@ |
||
42 | 42 | */ |
43 | 43 | class FilesDataHandler |
44 | 44 | { |
45 | - /** |
|
46 | - * @var Request |
|
47 | - */ |
|
48 | - protected $request; |
|
45 | + /** |
|
46 | + * @var Request |
|
47 | + */ |
|
48 | + protected $request; |
|
49 | 49 | |
50 | - /** |
|
51 | - * @var array |
|
52 | - */ |
|
53 | - protected $file_objects; |
|
50 | + /** |
|
51 | + * @var array |
|
52 | + */ |
|
53 | + protected $file_objects; |
|
54 | 54 | |
55 | - /** |
|
56 | - * @var bool |
|
57 | - */ |
|
58 | - protected $initialized = false; |
|
55 | + /** |
|
56 | + * @var bool |
|
57 | + */ |
|
58 | + protected $initialized = false; |
|
59 | 59 | |
60 | - /** |
|
61 | - * FilesDataHandler constructor. |
|
62 | - * @param Request $request |
|
63 | - */ |
|
64 | - public function __construct(Request $request) |
|
65 | - { |
|
66 | - $this->request = $request; |
|
67 | - } |
|
60 | + /** |
|
61 | + * FilesDataHandler constructor. |
|
62 | + * @param Request $request |
|
63 | + */ |
|
64 | + public function __construct(Request $request) |
|
65 | + { |
|
66 | + $this->request = $request; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @since $VID:$ |
|
71 | - * @return array with a similar structure to $_POST and $_GET (ie, it can be multi-dimensional) but the "leaf" |
|
72 | - * nodes are all of type FileSubmissionInterface |
|
73 | - * @throws CollectionDetailsException |
|
74 | - * @throws CollectionLoaderException |
|
75 | - * @throws UnexpectedValueException |
|
76 | - */ |
|
77 | - public function getFileObjects() |
|
78 | - { |
|
79 | - if (!$this->initialized) { |
|
80 | - $this->initialize(); |
|
81 | - } |
|
82 | - return $this->file_objects; |
|
83 | - } |
|
69 | + /** |
|
70 | + * @since $VID:$ |
|
71 | + * @return array with a similar structure to $_POST and $_GET (ie, it can be multi-dimensional) but the "leaf" |
|
72 | + * nodes are all of type FileSubmissionInterface |
|
73 | + * @throws CollectionDetailsException |
|
74 | + * @throws CollectionLoaderException |
|
75 | + * @throws UnexpectedValueException |
|
76 | + */ |
|
77 | + public function getFileObjects() |
|
78 | + { |
|
79 | + if (!$this->initialized) { |
|
80 | + $this->initialize(); |
|
81 | + } |
|
82 | + return $this->file_objects; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Sets up the file objects from the request's $_FILES data. |
|
87 | - * @since $VID:$ |
|
88 | - * @throws UnexpectedValueException |
|
89 | - */ |
|
90 | - protected function initialize() |
|
91 | - { |
|
92 | - $files_raw_data = $this->request->filesParams(); |
|
93 | - if (empty($files_raw_data)) { |
|
94 | - return; |
|
95 | - } |
|
96 | - if ($this->isStrangeFilesArray($files_raw_data)) { |
|
97 | - $data = $this->fixFilesDataArray($files_raw_data); |
|
98 | - } else { |
|
99 | - $data = $files_raw_data; |
|
100 | - } |
|
101 | - $this->file_objects = $this->createFileObjects($data); |
|
102 | - $this->initialized = true; |
|
103 | - } |
|
85 | + /** |
|
86 | + * Sets up the file objects from the request's $_FILES data. |
|
87 | + * @since $VID:$ |
|
88 | + * @throws UnexpectedValueException |
|
89 | + */ |
|
90 | + protected function initialize() |
|
91 | + { |
|
92 | + $files_raw_data = $this->request->filesParams(); |
|
93 | + if (empty($files_raw_data)) { |
|
94 | + return; |
|
95 | + } |
|
96 | + if ($this->isStrangeFilesArray($files_raw_data)) { |
|
97 | + $data = $this->fixFilesDataArray($files_raw_data); |
|
98 | + } else { |
|
99 | + $data = $files_raw_data; |
|
100 | + } |
|
101 | + $this->file_objects = $this->createFileObjects($data); |
|
102 | + $this->initialized = true; |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Detects if $_FILES is a weird multi-dimensional array that needs fixing or not. |
|
107 | - * @since $VID:$ |
|
108 | - * @param $files_data |
|
109 | - * @return bool |
|
110 | - * @throws UnexpectedValueException |
|
111 | - */ |
|
112 | - protected function isStrangeFilesArray($files_data) |
|
113 | - { |
|
114 | - if (!is_array($files_data)) { |
|
115 | - throw new UnexpectedValueException( |
|
116 | - sprintf( |
|
117 | - esc_html__( |
|
118 | - 'Unexpected PHP $_FILES data format. "%1$s" was expected to be an array.', |
|
119 | - 'event_espresso' |
|
120 | - ), |
|
121 | - (string) $files_data |
|
122 | - ) |
|
123 | - ); |
|
124 | - } |
|
125 | - $first_value = reset($files_data); |
|
126 | - if (!is_array($first_value)) { |
|
127 | - throw new UnexpectedValueException( |
|
128 | - sprintf( |
|
129 | - esc_html__( |
|
130 | - 'Unexpected PHP $_FILES data format. "%1$s" was expected to be an array.', |
|
131 | - 'event_espresso' |
|
132 | - ), |
|
133 | - (string) $first_value |
|
134 | - ) |
|
135 | - ); |
|
136 | - } |
|
137 | - $first_sub_array_item = reset($first_value); |
|
138 | - if (is_array($first_sub_array_item)) { |
|
139 | - // not just a 2d array |
|
140 | - return true; |
|
141 | - } |
|
142 | - // yep, just 2d array |
|
143 | - return false; |
|
144 | - } |
|
105 | + /** |
|
106 | + * Detects if $_FILES is a weird multi-dimensional array that needs fixing or not. |
|
107 | + * @since $VID:$ |
|
108 | + * @param $files_data |
|
109 | + * @return bool |
|
110 | + * @throws UnexpectedValueException |
|
111 | + */ |
|
112 | + protected function isStrangeFilesArray($files_data) |
|
113 | + { |
|
114 | + if (!is_array($files_data)) { |
|
115 | + throw new UnexpectedValueException( |
|
116 | + sprintf( |
|
117 | + esc_html__( |
|
118 | + 'Unexpected PHP $_FILES data format. "%1$s" was expected to be an array.', |
|
119 | + 'event_espresso' |
|
120 | + ), |
|
121 | + (string) $files_data |
|
122 | + ) |
|
123 | + ); |
|
124 | + } |
|
125 | + $first_value = reset($files_data); |
|
126 | + if (!is_array($first_value)) { |
|
127 | + throw new UnexpectedValueException( |
|
128 | + sprintf( |
|
129 | + esc_html__( |
|
130 | + 'Unexpected PHP $_FILES data format. "%1$s" was expected to be an array.', |
|
131 | + 'event_espresso' |
|
132 | + ), |
|
133 | + (string) $first_value |
|
134 | + ) |
|
135 | + ); |
|
136 | + } |
|
137 | + $first_sub_array_item = reset($first_value); |
|
138 | + if (is_array($first_sub_array_item)) { |
|
139 | + // not just a 2d array |
|
140 | + return true; |
|
141 | + } |
|
142 | + // yep, just 2d array |
|
143 | + return false; |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * Takes into account that $_FILES does a weird thing when you have hierarchical form names (eg `<input type="file" |
|
148 | - * name="my[hierarchical][form]">`): it leaves the top-level form part alone, but replaces the SECOND part with |
|
149 | - * "name", "size", "tmp_name", etc. So that file's data is located at "my[name][hierarchical][form]", |
|
150 | - * "my[size][hierarchical][form]", "my[tmp_name][hierarchical][form]", etc. It's really weird. |
|
151 | - * @since $VID:$ |
|
152 | - * @param $files_data |
|
153 | - * @return array |
|
154 | - */ |
|
155 | - protected function fixFilesDataArray($files_data) |
|
156 | - { |
|
157 | - $sane_files_array = []; |
|
158 | - foreach ($files_data as $top_key => $top_key_avlue) { |
|
159 | - foreach ($top_key_avlue as $lower_key => $lower_key_value) { |
|
160 | - foreach ($lower_key_value as $lowest_key => $lowest_key_value) { |
|
161 | - $next_data = [ |
|
162 | - $top_key => [ |
|
163 | - $lowest_key => $this->organizeFilesData($lowest_key_value, $lower_key, $lowest_key) |
|
164 | - ] |
|
165 | - ]; |
|
166 | - $sane_files_array = array_merge_recursive( |
|
167 | - $sane_files_array, |
|
168 | - $next_data |
|
169 | - ); |
|
170 | - } |
|
171 | - } |
|
172 | - } |
|
173 | - return $sane_files_array; |
|
174 | - } |
|
146 | + /** |
|
147 | + * Takes into account that $_FILES does a weird thing when you have hierarchical form names (eg `<input type="file" |
|
148 | + * name="my[hierarchical][form]">`): it leaves the top-level form part alone, but replaces the SECOND part with |
|
149 | + * "name", "size", "tmp_name", etc. So that file's data is located at "my[name][hierarchical][form]", |
|
150 | + * "my[size][hierarchical][form]", "my[tmp_name][hierarchical][form]", etc. It's really weird. |
|
151 | + * @since $VID:$ |
|
152 | + * @param $files_data |
|
153 | + * @return array |
|
154 | + */ |
|
155 | + protected function fixFilesDataArray($files_data) |
|
156 | + { |
|
157 | + $sane_files_array = []; |
|
158 | + foreach ($files_data as $top_key => $top_key_avlue) { |
|
159 | + foreach ($top_key_avlue as $lower_key => $lower_key_value) { |
|
160 | + foreach ($lower_key_value as $lowest_key => $lowest_key_value) { |
|
161 | + $next_data = [ |
|
162 | + $top_key => [ |
|
163 | + $lowest_key => $this->organizeFilesData($lowest_key_value, $lower_key, $lowest_key) |
|
164 | + ] |
|
165 | + ]; |
|
166 | + $sane_files_array = array_merge_recursive( |
|
167 | + $sane_files_array, |
|
168 | + $next_data |
|
169 | + ); |
|
170 | + } |
|
171 | + } |
|
172 | + } |
|
173 | + return $sane_files_array; |
|
174 | + } |
|
175 | 175 | |
176 | - /** |
|
177 | - * Recursively explores the array until it finds a leaf node, and tacks `$type` as a final index in front of it. |
|
178 | - * @since $VID:$ |
|
179 | - * @param $data either 'name', 'tmp_name', 'size', or 'error' |
|
180 | - * @param $type |
|
181 | - * @return array |
|
182 | - */ |
|
183 | - protected function organizeFilesData($data, $type) |
|
184 | - { |
|
185 | - $organized_data = []; |
|
186 | - foreach ($data as $key => $val) { |
|
187 | - if (is_array($val)) { |
|
188 | - $organized_data[ $key ] = $this->organizeFilesData($val, $type); |
|
189 | - } else { |
|
190 | - $organized_data[ $key ][ $type ] = $val; |
|
191 | - } |
|
192 | - } |
|
193 | - return $organized_data; |
|
194 | - } |
|
176 | + /** |
|
177 | + * Recursively explores the array until it finds a leaf node, and tacks `$type` as a final index in front of it. |
|
178 | + * @since $VID:$ |
|
179 | + * @param $data either 'name', 'tmp_name', 'size', or 'error' |
|
180 | + * @param $type |
|
181 | + * @return array |
|
182 | + */ |
|
183 | + protected function organizeFilesData($data, $type) |
|
184 | + { |
|
185 | + $organized_data = []; |
|
186 | + foreach ($data as $key => $val) { |
|
187 | + if (is_array($val)) { |
|
188 | + $organized_data[ $key ] = $this->organizeFilesData($val, $type); |
|
189 | + } else { |
|
190 | + $organized_data[ $key ][ $type ] = $val; |
|
191 | + } |
|
192 | + } |
|
193 | + return $organized_data; |
|
194 | + } |
|
195 | 195 | |
196 | - /** |
|
197 | - * Takes the organized $_FILES array (where all file info is located at the same spot as you'd expect an input |
|
198 | - * to be in $_GET or $_POST, with all the file's data located side-by-side in an array) and creates a |
|
199 | - * multi-dimensional array of FileSubmissionInterface objects. |
|
200 | - * @since $VID:$ |
|
201 | - * @param $organized_files |
|
202 | - * @return array |
|
203 | - * @throws UnexpectedValueException |
|
204 | - */ |
|
205 | - protected function createFileObjects($organized_files) |
|
206 | - { |
|
207 | - if (!is_array($organized_files)) { |
|
208 | - throw new UnexpectedValueException( |
|
209 | - sprintf( |
|
210 | - esc_html__( |
|
211 | - 'Unexpected PHP $organized_files data format. "%1$s" was expected to be an array.', |
|
212 | - 'event_espresso' |
|
213 | - ), |
|
214 | - (string) $organized_files |
|
215 | - ) |
|
216 | - ); |
|
217 | - } |
|
218 | - $objs = []; |
|
219 | - foreach ($organized_files as $key => $value) { |
|
220 | - if (isset($value['name'], $value['tmp_name'], $value['size'])) { |
|
221 | - $objs[ $key ] = new FileSubmission( |
|
222 | - $value['name'], |
|
223 | - $value['tmp_name'], |
|
224 | - $value['size'], |
|
225 | - $value['error'] |
|
226 | - ); |
|
227 | - } else { |
|
228 | - $objs[ $key ] = $this->createFileObjects($value); |
|
229 | - } |
|
230 | - } |
|
231 | - return $objs; |
|
232 | - } |
|
196 | + /** |
|
197 | + * Takes the organized $_FILES array (where all file info is located at the same spot as you'd expect an input |
|
198 | + * to be in $_GET or $_POST, with all the file's data located side-by-side in an array) and creates a |
|
199 | + * multi-dimensional array of FileSubmissionInterface objects. |
|
200 | + * @since $VID:$ |
|
201 | + * @param $organized_files |
|
202 | + * @return array |
|
203 | + * @throws UnexpectedValueException |
|
204 | + */ |
|
205 | + protected function createFileObjects($organized_files) |
|
206 | + { |
|
207 | + if (!is_array($organized_files)) { |
|
208 | + throw new UnexpectedValueException( |
|
209 | + sprintf( |
|
210 | + esc_html__( |
|
211 | + 'Unexpected PHP $organized_files data format. "%1$s" was expected to be an array.', |
|
212 | + 'event_espresso' |
|
213 | + ), |
|
214 | + (string) $organized_files |
|
215 | + ) |
|
216 | + ); |
|
217 | + } |
|
218 | + $objs = []; |
|
219 | + foreach ($organized_files as $key => $value) { |
|
220 | + if (isset($value['name'], $value['tmp_name'], $value['size'])) { |
|
221 | + $objs[ $key ] = new FileSubmission( |
|
222 | + $value['name'], |
|
223 | + $value['tmp_name'], |
|
224 | + $value['size'], |
|
225 | + $value['error'] |
|
226 | + ); |
|
227 | + } else { |
|
228 | + $objs[ $key ] = $this->createFileObjects($value); |
|
229 | + } |
|
230 | + } |
|
231 | + return $objs; |
|
232 | + } |
|
233 | 233 | } |
234 | 234 | // End of file FilesDataHandler.php |
235 | 235 | // Location: EventEspresso\core\services\request\files/FilesDataHandler.php |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | */ |
77 | 77 | public function getFileObjects() |
78 | 78 | { |
79 | - if (!$this->initialized) { |
|
79 | + if ( ! $this->initialized) { |
|
80 | 80 | $this->initialize(); |
81 | 81 | } |
82 | 82 | return $this->file_objects; |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | */ |
112 | 112 | protected function isStrangeFilesArray($files_data) |
113 | 113 | { |
114 | - if (!is_array($files_data)) { |
|
114 | + if ( ! is_array($files_data)) { |
|
115 | 115 | throw new UnexpectedValueException( |
116 | 116 | sprintf( |
117 | 117 | esc_html__( |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | ); |
124 | 124 | } |
125 | 125 | $first_value = reset($files_data); |
126 | - if (!is_array($first_value)) { |
|
126 | + if ( ! is_array($first_value)) { |
|
127 | 127 | throw new UnexpectedValueException( |
128 | 128 | sprintf( |
129 | 129 | esc_html__( |
@@ -185,9 +185,9 @@ discard block |
||
185 | 185 | $organized_data = []; |
186 | 186 | foreach ($data as $key => $val) { |
187 | 187 | if (is_array($val)) { |
188 | - $organized_data[ $key ] = $this->organizeFilesData($val, $type); |
|
188 | + $organized_data[$key] = $this->organizeFilesData($val, $type); |
|
189 | 189 | } else { |
190 | - $organized_data[ $key ][ $type ] = $val; |
|
190 | + $organized_data[$key][$type] = $val; |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | return $organized_data; |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | */ |
205 | 205 | protected function createFileObjects($organized_files) |
206 | 206 | { |
207 | - if (!is_array($organized_files)) { |
|
207 | + if ( ! is_array($organized_files)) { |
|
208 | 208 | throw new UnexpectedValueException( |
209 | 209 | sprintf( |
210 | 210 | esc_html__( |
@@ -218,14 +218,14 @@ discard block |
||
218 | 218 | $objs = []; |
219 | 219 | foreach ($organized_files as $key => $value) { |
220 | 220 | if (isset($value['name'], $value['tmp_name'], $value['size'])) { |
221 | - $objs[ $key ] = new FileSubmission( |
|
221 | + $objs[$key] = new FileSubmission( |
|
222 | 222 | $value['name'], |
223 | 223 | $value['tmp_name'], |
224 | 224 | $value['size'], |
225 | 225 | $value['error'] |
226 | 226 | ); |
227 | 227 | } else { |
228 | - $objs[ $key ] = $this->createFileObjects($value); |
|
228 | + $objs[$key] = $this->createFileObjects($value); |
|
229 | 229 | } |
230 | 230 | } |
231 | 231 | return $objs; |