Skip to content
PHP Ecosystem
Explore

UploadedFileCreator

API reference › PSR bridge › creator › UploadedFileCreator

final classyii2\extensions\psrbridge\creator\UploadedFileCreator
Sourcesrc/creator/UploadedFileCreator.php

Creates PSR-7 uploaded files from PHP file specifications.

MethodDescriptionDefined 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
public function __construct(Psr\Http\Message\UploadedFileFactoryInterface $uploadedFileFactory, Psr\Http\Message\StreamFactoryInterface $streamFactory)

Creates a new instance of the UploadedFileCreator class.

Parameters

ParameterTypeDescription
$uploadedFileFactoryPsr\Http\Message\UploadedFileFactoryInterfaceFactory to create uploaded files.
$streamFactoryPsr\Http\Message\StreamFactoryInterfaceFactory to create streams.
public function createFromArray(yii2\extensions\psrbridge\creator\FileSpec $file): Psr\Http\Message\UploadedFileInterface

Creates 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

ParameterTypeDescription
$fileyii2\extensions\psrbridge\creator\FileSpecFile 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

public function createFromGlobals(yii2\extensions\psrbridge\creator\FilesArray $files = []): yii2\extensions\psrbridge\creator\FilesArray

Creates UploadedFileInterface instances from PHP global files array.

Iterates over the provided files array and processes each entry using processFileInput.

Parameters

ParameterTypeDescription
$filesyii2\extensions\psrbridge\creator\FilesArrayUploaded file specifications or PSR-7 uploaded files.

Returns

yii2\extensions\psrbridge\creator\FilesArray: Processed uploaded files, preserving nested file trees.

Throws