|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZSOAPRequest class 00004 // 00005 // Created on: <19-Feb-2002 15:42:03 bf> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ Publish 00009 // SOFTWARE RELEASE: 4.0.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 /*! 00032 \class eZSOAPRequest ezsoaprequest.php 00033 \ingroup eZSOAP 00034 \brief eZSOAPRequest handles SOAP request messages 00035 00036 */ 00037 00038 require_once( "lib/ezutils/classes/ezdebug.php" ); 00039 //include_once( "lib/ezxml/classes/ezxml.php" ); 00040 //include_once( "lib/ezsoap/classes/ezsoapparameter.php" ); 00041 //include_once( 'lib/ezsoap/classes/ezsoapcodec.php' ); 00042 //include_once( "lib/ezsoap/classes/ezsoapenvelope.php" ); 00043 00044 class eZSOAPRequest extends eZSOAPEnvelope 00045 { 00046 /*! 00047 Constructs a new eZSOAPRequest object. You have to provide the request name 00048 and the target namespace for the request. 00049 00050 \param name 00051 \param namespace 00052 \param parameters, assosiative array, example: array( 'param1' => 'value1, 'param2' => 'value2' ) 00053 */ 00054 function eZSOAPRequest( $name="", $namespace="", $parameters = array() ) 00055 { 00056 $this->Name = $name; 00057 $this->Namespace = $namespace; 00058 00059 // call the parents constructor 00060 $this->eZSOAPEnvelope(); 00061 00062 foreach( $parameters as $name => $value ) 00063 { 00064 $this->addParameter( $name, $value ); 00065 } 00066 } 00067 00068 /*! 00069 Returns the request name. 00070 */ 00071 function name() 00072 { 00073 return $this->Name; 00074 } 00075 00076 /*! 00077 Returns the request target namespace. 00078 */ 00079 function namespace() 00080 { 00081 return $this->Namespace; 00082 } 00083 00084 /*! 00085 Adds a new attribute to the body element. 00086 00087 \param attribute name 00088 \param attribute value 00089 \param prefix 00090 */ 00091 function addBodyAttribute( $name, $value, $prefix = false ) 00092 { 00093 $this->BodyAttributes[( $prefix ? $prefix . ':' : '' ) . $name] = $value; 00094 } 00095 00096 /*! 00097 Adds a new parameter to the request. You have to provide a prameter name 00098 and value. 00099 */ 00100 function addParameter( $name, $value ) 00101 { 00102 $this->Parameters[] = new eZSOAPParameter( $name, $value ); 00103 } 00104 00105 /*! 00106 Returns the request payload 00107 */ 00108 function payload() 00109 { 00110 $doc = new DOMDocument( "1.0" ); 00111 $doc->name = 'eZSOAP message'; 00112 00113 $root = $doc->createElementNS( eZSOAPEnvelope::ENV, eZSOAPEnvelope::ENV_PREFIX . ':Envelope' ); 00114 00115 $root->setAttribute( 'xmlns:' . eZSOAPEnvelope::XSI_PREFIX, eZSOAPEnvelope::SCHEMA_INSTANCE ); 00116 $root->setAttribute( 'xmlns:' . eZSOAPEnvelope::XSD_PREFIX, eZSOAPEnvelope::SCHEMA_DATA ); 00117 $root->setAttribute( 'xmlns:' . eZSOAPEnvelope::ENC_PREFIX, eZSOAPEnvelope::ENC ); 00118 00119 // add the body 00120 $body = $doc->createElement( eZSOAPEnvelope::ENV_PREFIX . ':Body' ); 00121 $body->setAttribute( 'xmlns:req', $this->Namespace ); 00122 00123 foreach( $this->BodyAttributes as $name => $value ) 00124 { 00125 $body->setAttribute( $name, $value ); 00126 } 00127 00128 $root->appendChild( $body ); 00129 00130 // add the request 00131 $request = $doc->createElement( 'req:' . $this->Name ); 00132 00133 // add the request parameters 00134 foreach ( $this->Parameters as $parameter ) 00135 { 00136 $param = eZSOAPCodec::encodeValue( $doc, $parameter->name(), $parameter->value() ); 00137 00138 if ( $param == false ) 00139 { 00140 eZDebug::writeError( "Error encoding data for payload: " . $parameter->name(), "eZSOAPRequest::payload()" ); 00141 continue; 00142 } 00143 $request->appendChild( $param ); 00144 } 00145 00146 $body->appendChild( $request ); 00147 00148 $doc->appendChild( $root ); 00149 return $doc->saveXML(); 00150 } 00151 00152 /// The request name 00153 public $Name; 00154 00155 /// The request target namespace 00156 public $Namespace; 00157 00158 /// Additional body element attributes. 00159 public $BodyAttributes = array(); 00160 00161 /// Contains the request parameters 00162 public $Parameters = array(); 00163 } 00164 00165 ?>