|
eZ Publish
[trunk]
|
00001 <?php 00002 /** 00003 * File containing the eZSOAPRequest class. 00004 * 00005 * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. 00006 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 00007 * @version //autogentag// 00008 * @package lib 00009 */ 00010 00011 /*! 00012 \class eZSOAPRequest ezsoaprequest.php 00013 \ingroup eZSOAP 00014 \brief eZSOAPRequest handles SOAP request messages 00015 00016 */ 00017 00018 class eZSOAPRequest extends eZSOAPEnvelope 00019 { 00020 /*! 00021 Constructs a new eZSOAPRequest object. You have to provide the request name 00022 and the target namespace for the request. 00023 00024 \param name 00025 \param namespace 00026 \param parameters, assosiative array, example: array( 'param1' => 'value1, 'param2' => 'value2' ) 00027 */ 00028 function eZSOAPRequest( $name="", $namespace="", $parameters = array() ) 00029 { 00030 $this->Name = $name; 00031 $this->Namespace = $namespace; 00032 00033 // call the parents constructor 00034 $this->eZSOAPEnvelope(); 00035 00036 foreach( $parameters as $name => $value ) 00037 { 00038 $this->addParameter( $name, $value ); 00039 } 00040 } 00041 00042 /*! 00043 Returns the request name. 00044 */ 00045 function name() 00046 { 00047 return $this->Name; 00048 } 00049 00050 /** Returns the request target namespace. 00051 * 00052 * @since 4.1.4 (renamed from namespace() for php 5.3 compatibility) 00053 * @return string 00054 */ 00055 function ns() 00056 { 00057 return $this->Namespace; 00058 } 00059 00060 /*! 00061 Adds a new attribute to the body element. 00062 00063 \param attribute name 00064 \param attribute value 00065 \param prefix 00066 */ 00067 function addBodyAttribute( $name, $value, $prefix = false ) 00068 { 00069 $this->BodyAttributes[( $prefix ? $prefix . ':' : '' ) . $name] = $value; 00070 } 00071 00072 /*! 00073 Adds a new parameter to the request. You have to provide a prameter name 00074 and value. 00075 */ 00076 function addParameter( $name, $value ) 00077 { 00078 $this->Parameters[] = new eZSOAPParameter( $name, $value ); 00079 } 00080 00081 /*! 00082 Returns the request payload 00083 */ 00084 function payload() 00085 { 00086 $doc = new DOMDocument( "1.0" ); 00087 $doc->name = 'eZSOAP message'; 00088 00089 $root = $doc->createElementNS( eZSOAPEnvelope::ENV, eZSOAPEnvelope::ENV_PREFIX . ':Envelope' ); 00090 00091 $root->setAttribute( 'xmlns:' . eZSOAPEnvelope::XSI_PREFIX, eZSOAPEnvelope::SCHEMA_INSTANCE ); 00092 $root->setAttribute( 'xmlns:' . eZSOAPEnvelope::XSD_PREFIX, eZSOAPEnvelope::SCHEMA_DATA ); 00093 $root->setAttribute( 'xmlns:' . eZSOAPEnvelope::ENC_PREFIX, eZSOAPEnvelope::ENC ); 00094 00095 // add the body 00096 $body = $doc->createElement( eZSOAPEnvelope::ENV_PREFIX . ':Body' ); 00097 $body->setAttribute( 'xmlns:req', $this->Namespace ); 00098 00099 foreach( $this->BodyAttributes as $name => $value ) 00100 { 00101 $body->setAttribute( $name, $value ); 00102 } 00103 00104 $root->appendChild( $body ); 00105 00106 // add the request 00107 $request = $doc->createElement( 'req:' . $this->Name ); 00108 00109 // add the request parameters 00110 foreach ( $this->Parameters as $parameter ) 00111 { 00112 $param = eZSOAPCodec::encodeValue( $doc, $parameter->name(), $parameter->value() ); 00113 00114 if ( $param == false ) 00115 { 00116 eZDebug::writeError( "Error encoding data for payload: " . $parameter->name(), __METHOD__ ); 00117 continue; 00118 } 00119 $request->appendChild( $param ); 00120 } 00121 00122 $body->appendChild( $request ); 00123 00124 $doc->appendChild( $root ); 00125 return $doc->saveXML(); 00126 } 00127 00128 /// The request name 00129 public $Name; 00130 00131 /// The request target namespace 00132 public $Namespace; 00133 00134 /// Additional body element attributes. 00135 public $BodyAttributes = array(); 00136 00137 /// Contains the request parameters 00138 public $Parameters = array(); 00139 } 00140 00141 ?>