|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Class UploadedFileFactory |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource UploadedFileFactory.php |
|
6
|
|
|
* @created 27.08.2018 |
|
7
|
|
|
* @package chillerlan\HTTP\Psr17 |
|
8
|
|
|
* @author smiley <[email protected]> |
|
9
|
|
|
* @copyright 2018 smiley |
|
10
|
|
|
* @license MIT |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace chillerlan\HTTP\Psr17; |
|
14
|
|
|
|
|
15
|
|
|
use chillerlan\HTTP\Psr7\UploadedFile; |
|
16
|
|
|
use Psr\Http\Message\{StreamInterface, UploadedFileFactoryInterface, UploadedFileInterface}; |
|
17
|
|
|
|
|
18
|
|
|
final class UploadedFileFactory implements UploadedFileFactoryInterface{ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Create a new uploaded file. |
|
22
|
|
|
* |
|
23
|
|
|
* If a size is not provided it will be determined by checking the size of |
|
24
|
|
|
* the file. |
|
25
|
|
|
* |
|
26
|
|
|
* @see http://php.net/manual/features.file-upload.post-method.php |
|
27
|
|
|
* @see http://php.net/manual/features.file-upload.errors.php |
|
28
|
|
|
* |
|
29
|
|
|
* @param StreamInterface $stream Underlying stream representing the |
|
|
|
|
|
|
30
|
|
|
* uploaded file content. |
|
31
|
|
|
* @param int $size in bytes |
|
|
|
|
|
|
32
|
|
|
* @param int $error PHP file upload error |
|
33
|
|
|
* @param string $clientFilename Filename as provided by the client, if any. |
|
|
|
|
|
|
34
|
|
|
* @param string $clientMediaType Media type as provided by the client, if any. |
|
|
|
|
|
|
35
|
|
|
* |
|
36
|
|
|
* |
|
37
|
|
|
* @return \Psr\Http\Message\UploadedFileInterface|\chillerlan\HTTP\Psr7\UploadedFile |
|
38
|
|
|
* |
|
39
|
|
|
* @throws \InvalidArgumentException If the file resource is not readable. |
|
40
|
|
|
*/ |
|
41
|
|
|
public function createUploadedFile(StreamInterface $stream, int $size = null, int $error = \UPLOAD_ERR_OK, string $clientFilename = null, string $clientMediaType = null):UploadedFileInterface{ |
|
42
|
|
|
return new UploadedFile($stream, $size, $error, $clientFilename, $clientMediaType); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.