FormData
in package
implements
Countable
Provides an interface for building multipart/form-encoded message bodies.
Used by Http\Client to upload POST/PUT data and files.
Table of Contents
Interfaces
- Countable
Properties
- $_boundary : string
- Boundary marker.
- $_hasComplexPart : bool
- Whether this formdata object has a complex part.
- $_hasFile : bool
- Whether this formdata object has attached files.
- $_parts : array<string|int, FormDataPart>
- The parts in the form data.
Methods
- __toString() : string
- Converts the FormData and its parts into a string suitable for use in an HTTP request.
- add() : $this
- Add a new part to the data.
- addFile() : FormDataPart
- Add either a file reference (string starting with @) or a file handle.
- addMany() : $this
- Add multiple parts at once.
- addRecursive() : void
- Recursively add data.
- boundary() : string
- Get the boundary marker
- contentType() : string
- Get the content type for this payload.
- count() : int
- Returns the count of parts inside this object.
- hasFile() : bool
- Check whether the current payload has any files.
- isMultipart() : bool
- Check whether the current payload is multipart.
- newPart() : FormDataPart
- Method for creating new instances of Part
Properties
$_boundary
Boundary marker.
protected
string
$_boundary
$_hasComplexPart
Whether this formdata object has a complex part.
protected
bool
$_hasComplexPart
= false
$_hasFile
Whether this formdata object has attached files.
protected
bool
$_hasFile
= false
$_parts
The parts in the form data.
protected
array<string|int, FormDataPart>
$_parts
= []
Methods
__toString()
Converts the FormData and its parts into a string suitable for use in an HTTP request.
public
__toString() : string
Return values
stringadd()
Add a new part to the data.
public
add(FormDataPart|string $name[, mixed $value = null ]) : $this
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
- $name : FormDataPart|string
-
The name of the part to add, or the part data object.
- $value : mixed = null
-
The value for the part.
Return values
$thisaddFile()
Add either a file reference (string starting with @) or a file handle.
public
addFile(string $name, string|resource|UploadedFileInterface $value) : FormDataPart
Parameters
- $name : string
-
The name to use.
- $value : string|resource|UploadedFileInterface
-
Either a string filename, or a filehandle, or a UploadedFileInterface instance.
Return values
FormDataPartaddMany()
Add multiple parts at once.
public
addMany(array<string|int, mixed> $data) : $this
Iterates the parameter and adds all the key/values.
Parameters
- $data : array<string|int, mixed>
-
Array of data to add.
Return values
$thisaddRecursive()
Recursively add data.
public
addRecursive(string $name, mixed $value) : void
Parameters
- $name : string
-
The name to use.
- $value : mixed
-
The value to add.
boundary()
Get the boundary marker
public
boundary() : string
Return values
stringcontentType()
Get the content type for this payload.
public
contentType() : string
If this object contains files, multipart/form-data
will be used,
otherwise application/x-www-form-urlencoded
will be used.
Return values
stringcount()
Returns the count of parts inside this object.
public
count() : int
Return values
inthasFile()
Check whether the current payload has any files.
public
hasFile() : bool
Return values
bool —Whether there is a file in this payload.
isMultipart()
Check whether the current payload is multipart.
public
isMultipart() : bool
A payload will become multipart when you add files or use add() with a Part instance.
Return values
bool —Whether the payload is multipart.
newPart()
Method for creating new instances of Part
public
newPart(string $name, string $value) : FormDataPart
Parameters
- $name : string
-
The name of the part.
- $value : string
-
The value to add.