Public Member Functions | Data Fields

nusoapservermime Class Reference

nusoapservermime server supporting MIME attachments defined at http://www.w3.org/TR/SOAP-attachments. More...

Inheritance diagram for nusoapservermime:
Collaboration diagram for nusoapservermime:

Public Member Functions

 addAttachment ($data, $filename= '', $contenttype= 'application/octet-stream', $cid=false)
 adds a MIME attachment to the current response.
 clearAttachments ()
 clears the MIME attachments for the current response.
 getAttachments ()
 gets the MIME attachments from the current request.
 getHTTPBody ($soapmsg)
 gets the HTTP body for the current response.
 getHTTPContentType ()
 gets the HTTP content type for the current response.
 getHTTPContentTypeCharset ()
 gets the HTTP content type charset for the current response.
 parseRequest ($headers, $data)
 processes SOAP message received from client

Data Fields

 $requestAttachments = array()
 $responseAttachments
 $mimeContentType

Detailed Description

nusoapservermime server supporting MIME attachments defined at http://www.w3.org/TR/SOAP-attachments.

It depends on the PEAR Mail_MIME library.

Author:
Scott Nichol <snichol@sourceforge.net>
Thanks to Guillaume and Henning Reich for posting great attachment code to the mail list
Version:
Id:
nusoapmime.php 14918 2007-10-07 17:02:40Z rkuester

public

Definition at line 268 of file nusoapmime.php.


Member Function Documentation

nusoapservermime::addAttachment ( data,
filename = '',
contenttype = 'application/octet-stream',
cid = false 
)

adds a MIME attachment to the current response.

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.

Parameters:
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)
Returns:
string The content-id (cid) of the attachment public

Definition at line 302 of file nusoapmime.php.

References $data, and $filename.

                                                                                                               {
                if (! $cid) {
                        $cid = md5(uniqid(time()));
                }

                $info['data'] = $data;
                $info['filename'] = $filename;
                $info['contenttype'] = $contenttype;
                $info['cid'] = $cid;
                
                $this->responseAttachments[] = $info;

                return $cid;
        }

nusoapservermime::clearAttachments (  ) 

clears the MIME attachments for the current response.

public

Definition at line 322 of file nusoapmime.php.

                                    {
                $this->responseAttachments = array();
        }

nusoapservermime::getAttachments (  ) 

gets the MIME attachments from the current request.

Each array element in the return is an associative array with keys data, filename, contenttype, cid. These keys correspond to the parameters for addAttachment.

Returns:
array The attachments. public

Definition at line 336 of file nusoapmime.php.

                                  {
                return $this->requestAttachments;
        }

nusoapservermime::getHTTPBody ( soapmsg  ) 

gets the HTTP body for the current response.

Parameters:
string $soapmsg The SOAP payload
Returns:
string The HTTP body, which includes the SOAP payload private

Reimplemented from soap_server.

Definition at line 347 of file nusoapmime.php.

References $data, and nusoap_base::debug().

                                       {
                if (count($this->responseAttachments) > 0) {
                        $params['content_type'] = 'multipart/related; type=text/xml';
                        $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->responseAttachments 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);
        }

Here is the call graph for this function:

nusoapservermime::getHTTPContentType (  ) 

gets the HTTP content type for the current response.

Note: getHTTPBody must be called before this.

Returns:
string the HTTP content type for the current response. private

Reimplemented from soap_server.

Definition at line 406 of file nusoapmime.php.

                                      {
                if (count($this->responseAttachments) > 0) {
                        return $this->mimeContentType;
                }
                return parent::getHTTPContentType();
        }

nusoapservermime::getHTTPContentTypeCharset (  ) 

gets the HTTP content type charset for the current response.

returns false for non-text content types.

Note: getHTTPBody must be called before this.

Returns:
string the HTTP content type charset for the current response. private

Reimplemented from soap_server.

Definition at line 422 of file nusoapmime.php.

                                             {
                if (count($this->responseAttachments) > 0) {
                        return false;
                }
                return parent::getHTTPContentTypeCharset();
        }

nusoapservermime::parseRequest ( headers,
data 
)

processes SOAP message received from client

Parameters:
array $headers The HTTP headers
string $data unprocessed request data from client
Returns:
mixed value of the message, decoded into a PHP type private

Reimplemented from soap_server.

Definition at line 437 of file nusoapmime.php.

References $data, soap_server::$headers, nusoap_base::debug(), and nusoap_base::setError().

                                           {
                $this->debug('Entering parseRequest() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']);
                $this->requestAttachments = 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::parseRequest($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->requestAttachments[] = $info;
                                }
                        }
                
                        if (isset($return)) {
                                return $return;
                        }
                        
                        $this->setError('No root part found in multipart/related content');
                        return;
                }
                $this->debug('Not multipart/related');
                return parent::parseRequest($headers, $data);
        }

Here is the call graph for this function:


Field Documentation

nusoapservermime::$mimeContentType

Definition at line 285 of file nusoapmime.php.

nusoapservermime::$requestAttachments = array()

Definition at line 274 of file nusoapmime.php.

nusoapservermime::$responseAttachments

Definition at line 280 of file nusoapmime.php.


The documentation for this class was generated from the following file: