Code

< 40 %
40-60 %
> 60 %
1
<?php
2
3
/*
4
 * This file is part of the Koded package.
5
 *
6
 * (c) Mihail Binev <[email protected]>
7
 *
8
 * Please view the LICENSE distributed with this source code
9
 * for the full copyright and license information.
10
 *
11
 */
12
13
namespace Koded\Http;
14
15
use Psr\Http\Message\UploadedFileInterface;
16
17
18
trait FilesTrait
19
{
20
    /** @var UploadedFileInterface[] */
21
    protected array $uploadedFiles = [];
22
23
    public function getUploadedFiles(): array
24 8
    {
25
        return $this->uploadedFiles;
26 8
    }
27
28
    public function withUploadedFiles(array $uploadedFiles): static
29 2
    {
30
        $instance                = clone $this;
31 2
        $instance->uploadedFiles = $this->parseUploadedFiles($uploadedFiles);
32 2
        return $instance;
33
    }
34 2
35
    /**
36
     * Transforms the confusing _FILES array into a list
37
     * with UploadedFileInterface instances.
38
     *
39
     * @param array $uploadedFiles
40
     *
41
     * @return UploadedFileInterface[]
42
     */
43
    protected function parseUploadedFiles(array $uploadedFiles): array
44
    {
45 6
        return build_files_array(normalize_files_array($uploadedFiles));
46
    }
47
}
48