32e4c315f48e853cfb232ade174db016480bae97
[GitHub/WoltLab/WCF.git] /
1 <?php
2
3 /**
4 * @see https://github.com/laminas/laminas-diactoros for the canonical source repository
5 * @copyright https://github.com/laminas/laminas-diactoros/blob/master/COPYRIGHT.md
6 * @license https://github.com/laminas/laminas-diactoros/blob/master/LICENSE.md New BSD License
7 */
8
9 declare(strict_types=1);
10
11 namespace Laminas\Diactoros;
12
13 /**
14 * Create an uploaded file instance from an array of values.
15 *
16 * @param array $spec A single $_FILES entry.
17 * @throws Exception\InvalidArgumentException if one or more of the tmp_name,
18 * size, or error keys are missing from $spec.
19 */
20 function createUploadedFile(array $spec) : UploadedFile
21 {
22 if (! isset($spec['tmp_name'])
23 || ! isset($spec['size'])
24 || ! isset($spec['error'])
25 ) {
26 throw new Exception\InvalidArgumentException(sprintf(
27 '$spec provided to %s MUST contain each of the keys "tmp_name",'
28 . ' "size", and "error"; one or more were missing',
29 __FUNCTION__
30 ));
31 }
32
33 return new UploadedFile(
34 $spec['tmp_name'],
35 (int) $spec['size'],
36 $spec['error'],
37 $spec['name'] ?? null,
38 $spec['type'] ?? null
39 );
40 }