\Cake\Http\ClientFormData

Provides an interface for building multipart/form-encoded message bodies.

Used by Http\Client to upload POST/PUT data and files.

Summary

Methods
Properties
Constants
boundary()
newPart()
add()
addMany()
addFile()
addRecursive()
count()
hasFile()
isMultipart()
contentType()
__toString()
No public properties found
No constants found
No protected methods found
$_boundary
$_hasFile
$_hasComplexPart
$_parts
N/A
No private methods found
No private properties found
N/A

Properties

$_boundary

$_boundary : string

Boundary marker.

Type

string

$_hasFile

$_hasFile : boolean

Whether or not this formdata object has attached files.

Type

boolean

$_hasComplexPart

$_hasComplexPart : boolean

Whether or not this formdata object has a complex part.

Type

boolean

Methods

boundary()

boundary() : string

Get the boundary marker

Returns

string

newPart()

newPart(string  $name, string  $value) : \Cake\Http\Client\FormDataPart

Method for creating new instances of Part

Parameters

string $name

The name of the part.

string $value

The value to add.

Returns

\Cake\Http\Client\FormDataPart

add()

add(string|\Cake\Http\Client\FormData  $name, mixed  $value = null) : $this

Add a new part to the data.

The value for a part can be a string, array, int, float, filehandle, or object implementing __toString()

If the $value is an array, multiple parts will be added. Files will be read from their current position and saved in memory.

Parameters

string|\Cake\Http\Client\FormData $name

The name of the part to add, or the part data object.

mixed $value

The value for the part.

Returns

$this

addMany()

addMany(array  $data) : $this

Add multiple parts at once.

Iterates the parameter and adds all the key/values.

Parameters

array $data

Array of data to add.

Returns

$this

addFile()

addFile(string  $name, mixed  $value) : \Cake\Http\Client\FormDataPart

Add either a file reference (string starting with @) or a file handle.

Parameters

string $name

The name to use.

mixed $value

Either a string filename, or a filehandle.

Returns

\Cake\Http\Client\FormDataPart

addRecursive()

addRecursive(string  $name, mixed  $value) : void

Recursively add data.

Parameters

string $name

The name to use.

mixed $value

The value to add.

count()

count() : integer

Returns the count of parts inside this object.

Returns

integer

hasFile()

hasFile() : boolean

Check whether or not the current payload has any files.

Returns

boolean —

Whether or not there is a file in this payload.

isMultipart()

isMultipart() : boolean

Check whether or not the current payload is multipart.

A payload will become multipart when you add files or use add() with a Part instance.

Returns

boolean —

Whether or not the payload is multipart.

contentType()

contentType() : string

Get the content type for this payload.

If this object contains files, multipart/form-data will be used, otherwise application/x-www-form-urlencoded will be used.

Returns

string

__toString()

__toString() : string

Converts the FormData and its parts into a string suitable for use in an HTTP request.

Returns

string