-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUploadedFileFactory.php
More file actions
56 lines (52 loc) · 2.09 KB
/
UploadedFileFactory.php
File metadata and controls
56 lines (52 loc) · 2.09 KB
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
48
49
50
51
52
53
54
55
56
<?php
declare(strict_types=1);
/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP(tm) Project
* @since 5.0.0
* @license https://opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Http;
use Laminas\Diactoros\UploadedFile;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UploadedFileFactoryInterface;
use Psr\Http\Message\UploadedFileInterface;
/**
* Factory class for creating uploaded file instances.
*/
class UploadedFileFactory implements UploadedFileFactoryInterface
{
/**
* Create a new uploaded file.
*
* If a size is not provided it will be determined by checking the size of
* the stream.
*
* @link http://php.net/manual/features.file-upload.post-method.php
* @link http://php.net/manual/features.file-upload.errors.php
* @param \Psr\Http\Message\StreamInterface $stream The underlying stream representing the
* uploaded file content.
* @param int|null $size The size of the file in bytes.
* @param int $error The PHP file upload error.
* @param string|null $clientFilename The filename as provided by the client, if any.
* @param string|null $clientMediaType The media type as provided by the client, if any.
* @throws \InvalidArgumentException If the file resource is not readable.
*/
public function createUploadedFile(
StreamInterface $stream,
?int $size = null,
int $error = UPLOAD_ERR_OK,
?string $clientFilename = null,
?string $clientMediaType = null,
): UploadedFileInterface {
$size ??= $stream->getSize() ?? 0;
return new UploadedFile($stream, $size, $error, $clientFilename, $clientMediaType);
}
}