PHP Class Amp\Artax\FormBody

Inheritance: implements Amp\Artax\AggregateBody
Show file Open project: amphp/artax Class Usage Examples

Public Methods

Method Description
__construct ( string $boundary = null )
addField ( string $name, string $value, string $contentType = 'text/plain' ) : self Add a data field to the form entity body
addFields ( array $data, string $contentType = 'text/plain' ) : self Add each element of a associative array as a data field to the form entity body
addFile ( string $name, string $filePath, string $contentType = 'application/octet-stream' ) : self Add a file field to the form entity body
addFiles ( array $data, string $contentType = 'application/octet-stream' ) : self Add each element of a associative array as a file field to the form entity body
getBody ( ) : Amp\Promise Retrieve the sendable Amp\Artax entity body representation
getHeaders ( ) : Amp\Promise Retrieve a key-value array of headers to add to the outbound request
getLength ( ) : Amp\Promise Retrieve the content length of the form entity body

Private Methods

Method Description
determineContentType ( )
generateMultipartFieldHeader ( $name, $contentType )
generateMultipartFileHeader ( $name, $fileName, $contentType )
generateMultipartIteratorFromFields ( array $fields )
getFormEncodedBodyString ( )
getMultipartFieldArray ( )
sumMultipartFieldLengths ( array $fields )

Method Details

__construct() public method

public __construct ( string $boundary = null )
$boundary string An optional multipart boundary string

addField() public method

Add a data field to the form entity body
public addField ( string $name, string $value, string $contentType = 'text/plain' ) : self
$name string
$value string
$contentType string
return self

addFields() public method

Add each element of a associative array as a data field to the form entity body
public addFields ( array $data, string $contentType = 'text/plain' ) : self
$data array
$contentType string
return self

addFile() public method

Add a file field to the form entity body
public addFile ( string $name, string $filePath, string $contentType = 'application/octet-stream' ) : self
$name string
$filePath string
$contentType string
return self

addFiles() public method

Add each element of a associative array as a file field to the form entity body
public addFiles ( array $data, string $contentType = 'application/octet-stream' ) : self
$data array
$contentType string
return self

getBody() public method

AggregateBody::getBody() implementations always return a Promise instance to allow for future resolution of non-blocking operations (e.g. when the entity body comprises filesystem resources).
public getBody ( ) : Amp\Promise
return Amp\Promise

getHeaders() public method

AggregateBody::getHeaders() implementations always return a Promise instance to allow for future resolution of non-blocking operations (e.g. when using filesystem stats to generate content-length headers).
public getHeaders ( ) : Amp\Promise
return Amp\Promise

getLength() public method

AggregateBody::getLength() implementations always return a Promise instance to allow for future resolution of non-blocking operations (e.g. when using filesystem stats to determine entity body length).
public getLength ( ) : Amp\Promise
return Amp\Promise