TYPO3  7.6
Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
HTTP_Request2_MultipartBody Class Reference

Public Member Functions

 __construct (array $params, array $uploads, $useBrackets=true)
 
 getLength ()
 
 getBoundary ()
 
 read ($length)
 
 rewind ()
 
 __toString ()
 

Static Private Member Functions

static _flattenArray ($name, $values, $useBrackets)
 

Private Attributes

 $_boundary
 
 $_params = array()
 
 $_uploads = array()
 
 $_headerParam = "--%s\r\nContent-Disposition: form-data; name=\"%s\"\r\n\r\n"
 
 $_headerUpload = "--%s\r\nContent-Disposition: form-data; name=\"%s\"; filename=\"%s\"\r\nContent-Type: %s\r\n\r\n"
 
 $_pos = array(0, 0)
 

Detailed Description

Definition at line 38 of file MultipartBody.php.

Constructor & Destructor Documentation

__construct ( array  $params,
array  $uploads,
  $useBrackets = true 
)

Constructor. Sets the arrays with POST data.

Parameters
array$paramsvalues of form fields set via HTTP_Request2::addPostParameter()
array$uploadsfile uploads set via HTTP_Request2::addUpload()
bool$useBracketswhether to append brackets to array variable names

Definition at line 90 of file MultipartBody.php.

Member Function Documentation

__toString ( )

Returns the body as string

Note that it reads all file uploads into memory so it is a good idea not to use this method with large file uploads and rely on read() instead.

Returns
string

Definition at line 231 of file MultipartBody.php.

References getLength(), read(), and rewind().

static _flattenArray (   $name,
  $values,
  $useBrackets 
)
staticprivate

Helper function to change the (probably multidimensional) associative array into the simple one.

Parameters
string$namename for item
mixed$valuesitem's values
bool$useBracketswhether to append [] to array variables' names
Returns
array array with the following items: array('item name', 'item value');

Definition at line 248 of file MultipartBody.php.

References elseif.

getBoundary ( )

Returns the boundary to use in Content-Type header

Returns
string

Definition at line 136 of file MultipartBody.php.

References $_boundary.

Referenced by getLength(), and read().

getLength ( )

Returns the length of the body to use in Content-Length header

Returns
integer

Definition at line 115 of file MultipartBody.php.

References getBoundary().

Referenced by __toString().

read (   $length)

Returns next chunk of request body

Parameters
integer$lengthNumber of bytes to read
Returns
string Up to $length bytes of data, empty string if at end
Exceptions
HTTP_Request2_LogicException

Definition at line 152 of file MultipartBody.php.

References elseif, getBoundary(), and HTTP_Request2_Exception\READ_ERROR.

Referenced by __toString().

rewind ( )

Sets the current position to the start of the body

This allows reusing the same body in another request

Definition at line 215 of file MultipartBody.php.

Referenced by __toString().

Member Data Documentation

$_boundary
private

Definition at line 44 of file MultipartBody.php.

Referenced by getBoundary().

$_headerParam = "--%s\r\nContent-Disposition: form-data; name=\"%s\"\r\n\r\n"
private

Definition at line 62 of file MultipartBody.php.

$_headerUpload = "--%s\r\nContent-Disposition: form-data; name=\"%s\"; filename=\"%s\"\r\nContent-Type: %s\r\n\r\n"
private

Definition at line 68 of file MultipartBody.php.

$_params = array()
private

Definition at line 50 of file MultipartBody.php.

$_pos = array(0, 0)
private

Definition at line 78 of file MultipartBody.php.

$_uploads = array()
private

Definition at line 56 of file MultipartBody.php.