UploadedFileCreator
API reference › PSR bridge › creator › UploadedFileCreator
Creates PSR-7 uploaded files from PHP file specifications.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Creates a new instance of the UploadedFileCreator class. | UploadedFileCreator |
createFromArray() | Creates an UploadedFileInterface instance from a file specification array. | UploadedFileCreator |
createFromGlobals() | Creates UploadedFileInterface instances from PHP global files array. | UploadedFileCreator |
Method details
Section titled “Method details”__construct()
Section titled “__construct() ”public function __construct(Psr\Http\Message\UploadedFileFactoryInterface $uploadedFileFactory, Psr\Http\Message\StreamFactoryInterface $streamFactory)Creates a new instance of the UploadedFileCreator class.
Parameters
| Parameter | Type | Description |
|---|---|---|
$uploadedFileFactory | Psr\ | Factory to create uploaded files. |
$streamFactory | Psr\ | Factory to create streams. |
createFromArray()
Section titled “createFromArray() ”public function createFromArray(yii2\extensions\psrbridge\creator\FileSpec $file): Psr\Http\Message\UploadedFileInterfaceCreates an UploadedFileInterface instance from a file specification array.
Validates the input file specification and delegates stream and uploaded file creation to the configured PSR-7 factories.
Parameters
| Parameter | Type | Description |
|---|---|---|
$file | yii2\ | File specification with required upload fields and optional name and type. |
Returns
Psr\Http\Message\UploadedFileInterface: Created uploaded file; failed uploads receive an empty stream.
Throws
yii\base\InvalidArgumentException: when the specification is invalid or a successful upload cannot be opened.
createFromGlobals()
Section titled “createFromGlobals() ”public function createFromGlobals(yii2\extensions\psrbridge\creator\FilesArray $files = []): yii2\extensions\psrbridge\creator\FilesArrayCreates UploadedFileInterface instances from PHP global files array.
Iterates over the provided files array and processes each entry using processFileInput.
Parameters
| Parameter | Type | Description |
|---|---|---|
$files | yii2\ | Uploaded file specifications or PSR-7 uploaded files. |
Returns
yii2\extensions\psrbridge\creator\FilesArray: Processed uploaded files, preserving nested file trees.
Throws
yii\base\InvalidArgumentException: when specifications are invalid, nesting exceeds 10, or a successful upload cannot be opened.