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