WordPress\AiClientDependencies\Nyholm\Psr7

UploadedFile::__constructpublicWP 1.0

Method of the class: UploadedFile{}

No Hooks.

Returns

null. Nothing (null).

Usage

$UploadedFile = new UploadedFile();
$UploadedFile->__construct( $streamOrFile, $size, $errorStatus, $clientFilename, $clientMediaType );
$streamOrFile(StreamInterface|string|resource) (required)
.
$size(int) (required)
.
$errorStatus(int) (required)
.
$clientFilename(string|null)
.
Default: null
$clientMediaType(string|null)
.
Default: null

UploadedFile::__construct() code WP 7.0

public function __construct($streamOrFile, $size, $errorStatus, $clientFilename = null, $clientMediaType = null)
{
    if (\false === \is_int($errorStatus) || !isset(self::ERRORS[$errorStatus])) {
        throw new \InvalidArgumentException('Upload file error status must be an integer value and one of the "UPLOAD_ERR_*" constants');
    }
    if (\false === \is_int($size)) {
        throw new \InvalidArgumentException('Upload file size must be an integer');
    }
    if (null !== $clientFilename && !\is_string($clientFilename)) {
        throw new \InvalidArgumentException('Upload file client filename must be a string or null');
    }
    if (null !== $clientMediaType && !\is_string($clientMediaType)) {
        throw new \InvalidArgumentException('Upload file client media type must be a string or null');
    }
    $this->error = $errorStatus;
    $this->size = $size;
    $this->clientFilename = $clientFilename;
    $this->clientMediaType = $clientMediaType;
    if (\UPLOAD_ERR_OK === $this->error) {
        // Depending on the value set file or stream variable.
        if (\is_string($streamOrFile) && '' !== $streamOrFile) {
            $this->file = $streamOrFile;
        } elseif (\is_resource($streamOrFile)) {
            $this->stream = Stream::create($streamOrFile);
        } elseif ($streamOrFile instanceof StreamInterface) {
            $this->stream = $streamOrFile;
        } else {
            throw new \InvalidArgumentException('Invalid stream or file provided for UploadedFile');
        }
    }
}