Support Incident Tracker GIT4.x
nusoap_server_mime Class Reference
Inheritance diagram for nusoap_server_mime:
Collaboration diagram for nusoap_server_mime:

Public Member Functions

 addAttachment ($data, $filename= '', $contenttype= 'application/octet-stream', $cid=false)
 clearAttachments ()
 getAttachments ()
 getHTTPBody ($soapmsg)
 getHTTPContentType ()
 getHTTPContentTypeCharset ()
 parseRequest ($headers, $data)

Data Fields

 $requestAttachments = array()
 $responseAttachments
 $mimeContentType

Detailed Description

nusoap_server_mime 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@users.sourceforge.net>
Thanks to Guillaume and Henning Reich for posting great attachment code to the mail list
Version:
Id:
nusoapmime.php,v 1.12 2007/04/17 16:34:03 snichol Exp

public

Definition at line 284 of file nusoapmime.php.


Member Function Documentation

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$dataThe data of the attachment
string$filenameThe filename of the attachment (default is empty string)
string$contenttypeThe MIME Content-Type of the attachment (default is application/octet-stream)
string$cidThe content-id (cid) of the attachment (default is false)
Returns:
string The content-id (cid) of the attachment public

Definition at line 318 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;
    }
clearAttachments ( )

clears the MIME attachments for the current response.

public

Definition at line 338 of file nusoapmime.php.

                                {
        $this->responseAttachments = array();
    }
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 352 of file nusoapmime.php.

                              {
        return $this->requestAttachments;
    }
getHTTPBody ( soapmsg)

gets the HTTP body for the current response.

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

Reimplemented from nusoap_server.

Definition at line 363 of file nusoapmime.php.

References $data, $output, count, 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);
    }
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 nusoap_server.

Definition at line 422 of file nusoapmime.php.

References count.

                                  {
        if (count($this->responseAttachments) > 0) {
            return $this->mimeContentType;
        }
        return parent::getHTTPContentType();
    }
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 nusoap_server.

Definition at line 438 of file nusoapmime.php.

References count.

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

processes SOAP message received from client

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

Reimplemented from nusoap_server.

Definition at line 453 of file nusoapmime.php.

References $data, nusoap_server::$headers, $return, 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) && (strstr($part->headers['content-type'], 'text/xml'))) {
                    $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);
    }

Field Documentation

$mimeContentType

Definition at line 301 of file nusoapmime.php.

$requestAttachments = array()

Definition at line 290 of file nusoapmime.php.

$responseAttachments

Definition at line 296 of file nusoapmime.php.


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