|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Phalcon Framework. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Phalcon Team <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE.txt |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
* Implementation of this file has been influenced by Zend Diactoros |
|
12
|
|
|
* |
|
13
|
|
|
* @link https://github.com/zendframework/zend-diactoros |
|
14
|
|
|
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
declare(strict_types=1); |
|
18
|
|
|
|
|
19
|
|
|
namespace Phalcon\Http\Message; |
|
20
|
|
|
|
|
21
|
|
|
use Phalcon\Http\Message\Exception\InvalidArgumentException; |
|
22
|
|
|
use Psr\Http\Message\StreamInterface; |
|
23
|
|
|
use Psr\Http\Message\UploadedFileFactoryInterface; |
|
24
|
|
|
use Psr\Http\Message\UploadedFileInterface; |
|
25
|
|
|
|
|
26
|
|
|
use const UPLOAD_ERR_OK; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* PSR-17 UploadedFileFactory |
|
30
|
|
|
*/ |
|
31
|
|
|
final class UploadedFileFactory implements UploadedFileFactoryInterface |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* Create a new uploaded file. |
|
35
|
|
|
* |
|
36
|
|
|
* If a size is not provided it will be determined by checking the size of |
|
37
|
|
|
* the stream. |
|
38
|
|
|
* |
|
39
|
|
|
* @link http://php.net/manual/features.file-upload.post-method.php |
|
40
|
|
|
* @link http://php.net/manual/features.file-upload.errors.php |
|
41
|
|
|
* |
|
42
|
|
|
* @param StreamInterface $stream The underlying stream |
|
43
|
|
|
* representing the uploaded file |
|
44
|
|
|
* content. |
|
45
|
|
|
* @param int|null $size The size of the file in bytes. |
|
46
|
|
|
* @param int $error The PHP file upload error. |
|
47
|
|
|
* @param string|null $clientFilename The filename as provided by the |
|
48
|
|
|
* client, if any. |
|
49
|
|
|
* @param string|null $clientMediaType The media type as provided by |
|
50
|
|
|
* the client, if any. |
|
51
|
|
|
* |
|
52
|
|
|
* @throws InvalidArgumentException If the file resource is not readable. |
|
53
|
|
|
* |
|
54
|
|
|
* @return UploadedFileInterface |
|
55
|
|
|
* |
|
56
|
|
|
* @throws InvalidArgumentException If the file resource is not readable. |
|
57
|
|
|
*/ |
|
58
|
1 |
|
public function createUploadedFile( |
|
59
|
|
|
StreamInterface $stream, |
|
60
|
|
|
int $size = null, |
|
61
|
|
|
int $error = UPLOAD_ERR_OK, |
|
62
|
|
|
string $clientFilename = null, |
|
63
|
|
|
string $clientMediaType = null |
|
64
|
|
|
): UploadedFileInterface { |
|
65
|
1 |
|
return new UploadedFile( |
|
66
|
1 |
|
$stream, |
|
67
|
|
|
$size, |
|
68
|
|
|
$error, |
|
69
|
|
|
$clientFilename, |
|
70
|
|
|
$clientMediaType |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|