class MultipartParserAndSender (View source)

Streams the multipart data from the source to the target and thus makes the transfer with lesser memory footprint.

Class MultipartParserAndSender

Properties

protected StreamClient $sourceClient
protected SocketClient $targetClient
protected resource $sourceConnection
protected resource $targetConnection

Methods

__construct(AbstractHTTPClient $source, AbstractHTTPClient $target)

No description

array|ErrorResponse|string
request(string $sourceMethod, string $sourcePath, string $targetPath, string $sourceData = null, array $sourceHeaders = [])

Perform request to the source, parse the multipart response, stream the documents with attachments to the target and return the responses along with docs that did not have any attachments.

string
getNextLineFromSourceConnection(int $maxLength = null)

Read and return next line from the connection pointer.

array
parseAndSend($targetPath)

Parses multipart data. Returns an array having: 1) Array of json docs(which are strings) that don't have attachments.

mixed|string
sendStream($method, $path, $streamEnd, array $requestHeaders = [])

Reads multipart data from sourceConnection and streams it to the targetConnection.Returns the body of the request or the status code in case there is no body.

Details

__construct(AbstractHTTPClient $source, AbstractHTTPClient $target)

Parameters

AbstractHTTPClient $source
AbstractHTTPClient $target

array|ErrorResponse|string request(string $sourceMethod, string $sourcePath, string $targetPath, string $sourceData = null, array $sourceHeaders = [])

Perform request to the source, parse the multipart response, stream the documents with attachments to the target and return the responses along with docs that did not have any attachments.

Parameters

string $sourceMethod
string $sourcePath
string $targetPath
string $sourceData
array $sourceHeaders

Return Value

array|ErrorResponse|string

Exceptions

HTTPException
Exception

protected string getNextLineFromSourceConnection(int $maxLength = null)

Read and return next line from the connection pointer.

$maxLength parameter can be used to set the maximum length to be read.

Parameters

int $maxLength

Return Value

string

protected array parseAndSend($targetPath)

Parses multipart data. Returns an array having: 1) Array of json docs(which are strings) that don't have attachments.

These should be posted using the Bulk API. 2) Responses of posting docs with attachments.

Parameters

$targetPath

Return Value

array

Exceptions

Exception
HTTPException

protected mixed|string sendStream($method, $path, $streamEnd, array $requestHeaders = [])

Reads multipart data from sourceConnection and streams it to the targetConnection.Returns the body of the request or the status code in case there is no body.

Parameters

$method
$path
$streamEnd
array $requestHeaders

Return Value

mixed|string

Exceptions

Exception
HTTPException