soapclientmime client supporting MIME attachments. More...
Public Member Functions | |
addAttachment ($data, $filename= '', $contenttype= 'application/octet-stream', $cid=false) | |
adds a MIME attachment to the current request. | |
clearAttachments () | |
clears the MIME attachments for the current request. | |
getAttachments () | |
gets the MIME attachments from the current response. | |
getHTTPBody ($soapmsg) | |
gets the HTTP body for the current request. | |
getHTTPContentType () | |
gets the HTTP content type for the current request. | |
getHTTPContentTypeCharset () | |
gets the HTTP content type charset for the current request. | |
parseResponse ($headers, $data) | |
processes SOAP message returned from server | |
Data Fields | |
$requestAttachments = array() | |
$responseAttachments | |
$mimeContentType |
soapclientmime client supporting MIME attachments.
=======
>>>>>>> 1.1.2.2 public
Definition at line 53 of file nusoapmime.php.
soapclientmime::addAttachment | ( | $ | data, | |
$ | filename = '' , |
|||
$ | contenttype = 'application/octet-stream' , |
|||
$ | cid = false | |||
) |
adds a MIME attachment to the current request.
If the $data parameter contains an empty string, this method will read the contents of the file named by the $filename parameter.
If the $cid parameter is false, this method will generate the cid.
string | $data The data of the attachment | |
string | $filename The filename of the attachment (default is empty string) | |
string | $contenttype The MIME Content-Type of the attachment (default is application/octet-stream) | |
string | $cid The content-id (cid) of the attachment (default is false) |
Definition at line 73 of file nusoapmime.php.
References $data.
{ if (! $cid) { $cid = md5(uniqid(time())); } $info['data'] = $data; $info['filename'] = $filename; $info['contenttype'] = $contenttype; $info['cid'] = $cid; $this->requestAttachments[] = $info; return $cid; }
soapclientmime::clearAttachments | ( | ) |
clears the MIME attachments for the current request.
public
Definition at line 93 of file nusoapmime.php.
{ $this->requestAttachments = array(); }
soapclientmime::getAttachments | ( | ) |
gets the MIME attachments from the current response.
Each array element in the return is an associative array with keys data, filename, contenttype, cid. These keys correspond to the parameters for addAttachment.
Definition at line 107 of file nusoapmime.php.
{
return $this->responseAttachments;
}
soapclientmime::getHTTPBody | ( | $ | soapmsg | ) |
gets the HTTP body for the current request.
string | $soapmsg The SOAP payload |
Reimplemented from soap_client.
Definition at line 118 of file nusoapmime.php.
References $data, $output, and nusoap_base::debug().
{ if (count($this->requestAttachments) > 0) { $params['content_type'] = 'multipart/related'; $mimeMessage =& new Mail_mimePart('', $params); unset($params); $params['content_type'] = 'text/xml'; $params['encoding'] = '8bit'; $params['charset'] = $this->soap_defencoding; $mimeMessage->addSubpart($soapmsg, $params); foreach ($this->requestAttachments as $att) { unset($params); $params['content_type'] = $att['contenttype']; $params['encoding'] = 'base64'; $params['disposition'] = 'attachment'; $params['dfilename'] = $att['filename']; $params['cid'] = $att['cid']; if ($att['data'] == '' && $att['filename'] <> '') { if ($fd = fopen($att['filename'], 'rb')) { $data = fread($fd, filesize($att['filename'])); fclose($fd); } else { $data = ''; } $mimeMessage->addSubpart($data, $params); } else { $mimeMessage->addSubpart($att['data'], $params); } } $output = $mimeMessage->encode(); $mimeHeaders = $output['headers']; foreach ($mimeHeaders as $k => $v) { $this->debug("MIME header $k: $v"); if (strtolower($k) == 'content-type') { // PHP header() seems to strip leading whitespace starting // the second line, so force everything to one line $this->mimeContentType = str_replace("\r\n", " ", $v); } } return $output['body']; } return parent::getHTTPBody($soapmsg); }
soapclientmime::getHTTPContentType | ( | ) |
gets the HTTP content type for the current request.
Note: getHTTPBody must be called before this.
Reimplemented from soap_client.
Definition at line 177 of file nusoapmime.php.
{ if (count($this->requestAttachments) > 0) { return $this->mimeContentType; } return parent::getHTTPContentType(); }
soapclientmime::getHTTPContentTypeCharset | ( | ) |
gets the HTTP content type charset for the current request.
returns false for non-text content types.
Note: getHTTPBody must be called before this.
Reimplemented from soap_client.
Definition at line 193 of file nusoapmime.php.
{ if (count($this->requestAttachments) > 0) { return false; } return parent::getHTTPContentTypeCharset(); }
soapclientmime::parseResponse | ( | $ | headers, | |
$ | data | |||
) |
processes SOAP message returned from server
array | $headers The HTTP headers | |
string | $data unprocessed response data from server |
Reimplemented from soap_client.
Definition at line 208 of file nusoapmime.php.
References $data, nusoap_base::debug(), and nusoap_base::setError().
{ $this->debug('Entering parseResponse() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']); $this->responseAttachments = array(); if (strstr($headers['content-type'], 'multipart/related')) { $this->debug('Decode multipart/related'); $input = ''; foreach ($headers as $k => $v) { $input .= "$k: $v\r\n"; } $params['input'] = $input . "\r\n" . $data; $params['include_bodies'] = true; $params['decode_bodies'] = true; $params['decode_headers'] = true; $structure = Mail_mimeDecode::decode($params); foreach ($structure->parts as $part) { if (!isset($part->disposition)) { $this->debug('Have root part of type ' . $part->headers['content-type']); $return = parent::parseResponse($part->headers, $part->body); } else { $this->debug('Have an attachment of type ' . $part->headers['content-type']); $info['data'] = $part->body; $info['filename'] = isset($part->d_parameters['filename']) ? $part->d_parameters['filename'] : ''; $info['contenttype'] = $part->headers['content-type']; $info['cid'] = $part->headers['content-id']; $this->responseAttachments[] = $info; } } if (isset($return)) { return $return; } $this->setError('No root part found in multipart/related content'); return; } $this->debug('Not multipart/related'); return parent::parseResponse($headers, $data); }
soapclientmime::$mimeContentType |
Definition at line 56 of file nusoapmime.php.
soapclientmime::$requestAttachments = array() |
Definition at line 54 of file nusoapmime.php.
soapclientmime::$responseAttachments |
Definition at line 55 of file nusoapmime.php.