Port to PEAR and more | // | Authors: Dietrich Ayala Original Author | // +----------------------------------------------------------------------+ // // $Id: Message.php,v 1.1.1.2 2006/06/08 14:56:39 06292871800 Exp $ // require_once 'SOAP/globals.php'; require_once 'SOAP/Base.php'; require_once 'SOAP/Parser.php'; require_once 'SOAP/Value.php'; /** * SOAP Message Class * this class serializes and deserializes soap messages for transport (see SOAP::Transport) * * originaly based on SOAPx4 by Dietrich Ayala http://dietrich.ganx4.com/soapx4 * * @access public * @version $Id: Message.php,v 1.1.1.2 2006/06/08 14:56:39 06292871800 Exp $ * @package SOAP::Message * @author Shane Caraveo Conversion to PEAR and updates * @author Dietrich Ayala Original Author */ class SOAP_Message extends SOAP_Base { /** * XML payload * * @var string */ var $payload = ''; /** * List of namespaced * * @var array */ var $namespaces; /** * SOAP value * * @var object SOAP_value */ var $value = ''; /** * SOAP::Message constructor * * initializes a soap structure containing the method signature and parameters * * @param string $method soap data (in xml) * @param array(SOAP::Value) $params soap data (in xml) * @param string $method_namespace soap data (in xml) * @param array of string $new_namespaces soap data (in xml) * * @access public */ function SOAP_Message($method, $params, $method_namespace = 'http://testuri.org', $new_namespaces = NULL, $wsdl = NULL) { parent::SOAP_Base('Message'); // make method struct $this->value = new SOAP_Value($method, 'Struct', $params, $method_namespace, NULL, $wsdl); if (is_array($new_namespaces)) { global $SOAP_namespaces; $i = count($SOAP_namespaces); foreach ($new_namespaces as $v) { $SOAP_namespaces[$v] = 'ns' . $i++; } $this->namespaces = $SOAP_namespaces; } $this->debug_data = 'entering SOAP_Message() with SOAP_Value ' . $this->value->name . "\n"; } /** * wraps the soap payload with the soap envelop data * * @param string $payload soap data (in xml) * @return string xml_soap_data * @access private */ function _makeEnvelope($payload) { global $SOAP_namespaces; $ns_string = ''; foreach ($SOAP_namespaces as $k => $v) { $ns_string .= "xmlns:$v=\"$k\"\n "; } return "\n" . $payload . "\n"; } /** * wraps the soap body * * @param string $payload soap data (in xml) * * @return string xml_soap_data * @access private */ function _makeBody($payload) { return "\n" . $payload . "\n"; } /** * creates an xml string representation of the soap message data * * @access private */ function _createPayload() { $value = $this->value; $payload = $this->_makeEnvelope($this->_makeBody($value->serialize())); $this->debug($value->debug_data); $payload = "\n\n" . $payload; if ($this->debug_flag) { $payload .= $this->serializeDebug(); } $this->payload = str_replace("\n", "\r\n", $payload); } /** * serializes this classes data into xml * * @return string xml_soap_data * @access public */ function serialize() { if ($this->payload == '') { $this->_createPayload(); return $this->payload; } return $this->payload; } /** * parses a soap message * * @param string $data soap message (in xml) * * @return SOAP::Value * @access public */ function parseResponse($data) { $this->debug('Entering parseResponse()'); $this->debug(" w/ data $data"); $this->debug('about to create parser instance w/ data'); // parse response $response = new SOAP_Parser($data); // return array of parameters $ret = $response->getResponse(); $this->debug($response->debug_data); return $ret; } /** * preps debug data for encoding into SOAP::Message * * @return string * @access private */ function serializeDebug() { if ($this->debug_flag) { return "\n"; } return ''; } } ?>