7b41a425e5368c824b6d6dc364b08ba3f7f342f9
[yaffs-website] / vendor / zendframework / zend-diactoros / src / functions / create_uploaded_file.php
1 <?php
2 /**
3  * @see       https://github.com/zendframework/zend-diactoros for the canonical source repository
4  * @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
5  * @license   https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
6  */
7
8 namespace Zend\Diactoros;
9
10 use InvalidArgumentException;
11
12 /**
13  * Create an uploaded file instance from an array of values.
14  *
15  * @param array $spec A single $_FILES entry.
16  * @return UploadedFile
17  * @throws InvalidArgumentException if one or more of the tmp_name, size,
18  *     or error keys are missing from $spec.
19  */
20 function createUploadedFile(array $spec)
21 {
22     if (! isset($spec['tmp_name'])
23         || ! isset($spec['size'])
24         || ! isset($spec['error'])
25     ) {
26         throw new 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         $spec['size'],
36         $spec['error'],
37         isset($spec['name']) ? $spec['name'] : null,
38         isset($spec['type']) ? $spec['type'] : null
39     );
40 }