00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 include_once( "lib/ezsoap/classes/ezsoaprequest.php" );
00071 include_once( "lib/ezsoap/classes/ezsoapfault.php" );
00072 include_once( "lib/ezsoap/classes/ezsoapresponse.php" );
00073 include_once( "lib/ezxml/classes/ezxml.php" );
00074
00075 class eZSOAPServer
00076 {
00077
00078
00079
00080 function eZSOAPServer()
00081 {
00082 global $HTTP_RAW_POST_DATA;
00083 $this->RawPostData = $HTTP_RAW_POST_DATA;
00084 }
00085
00086
00087 function showResponse( $functionName, $namespaceURI, &$value )
00088 {
00089
00090 $response = new eZSOAPResponse( $functionName, $namespaceURI );
00091 $response->setValue( $value );
00092
00093 $payload = $response->payload();
00094
00095 header( "SOAPServer: eZ soap" );
00096 header( "Content-Type: text/xml; charset=\"UTF-8\"" );
00097 Header( "Content-Length: " . strlen( $payload ) );
00098
00099 if ( ob_get_length() )
00100 ob_end_clean();
00101
00102 print( $payload );
00103 }
00104
00105
00106
00107
00108
00109
00110 function registerObject( $objectName, $includeFile = null )
00111 {
00112 if ( file_exists( $includeFile ) )
00113 include_once( $includeFile );
00114
00115 if ( class_exists( $objectName ) )
00116 {
00117 $methods = get_class_methods( $objectName );
00118 foreach ( $methods as $method)
00119 {
00120 if ( strcasecmp ( $objectName, $method ) )
00121 $this->registerFunction( $objectName."::".$method );
00122 }
00123 return true;
00124 }
00125 else
00126 {
00127 return false;
00128 }
00129 }
00130
00131
00132
00133
00134
00135 function processRequest()
00136 {
00137 global $HTTP_SERVER_VARS;
00138
00139 if ( $HTTP_SERVER_VARS["REQUEST_METHOD"] != "POST" )
00140 {
00141 print( "Error: this web page does only understand POST methods" );
00142 exit();
00143 }
00144
00145 $xmlData = $this->stripHTTPHeader( $this->RawPostData );
00146
00147 $xml = new eZXML();
00148
00149 $dom = $xml->domTree( $xmlData );
00150
00151
00152 if ( !is_object( $dom ) )
00153 {
00154 $this->showResponse( 'unknown_function_name', 'unknown_namespace_uri',
00155 new eZSOAPFault( 'Server Error',
00156 'Bad XML' ) );
00157 return;
00158 }
00159
00160
00161
00162 $body = $dom->elementsByName( "Body" );
00163
00164 $children = $body[0]->children();
00165
00166 if ( count( $children ) == 1 )
00167 {
00168 $requestNode = $children[0];
00169
00170 $functionName = $requestNode->name();
00171 $namespaceURI = $requestNode->namespaceURI();
00172
00173 $params = array();
00174
00175 foreach ( $requestNode->children() as $parameterNode )
00176 {
00177 $params[] = eZSOAPResponse::decodeDataTypes( $parameterNode );
00178 }
00179
00180 list( $objectName, $objectFunctionName ) = preg_split('/::/', $functionName, 2, PREG_SPLIT_NO_EMPTY);
00181 if ( !$objectFunctionName and in_array( $functionName, $this->FunctionList ) &&
00182 function_exists( $functionName ) )
00183 {
00184 $this->showResponse( $functionName, $namespaceURI,
00185 call_user_func_array( $functionName, $params ) );
00186 }
00187 else if ( $objectName and $objectFunctionName )
00188 {
00189 if ( !class_exists( $objectName ) )
00190 {
00191 $this->showResponse( $functionName, $namespaceURI,
00192 new eZSOAPFault( 'Server Error',
00193 'Object not found' ) );
00194 }
00195 else
00196 {
00197 $object = new $objectName();
00198 if ( !method_exists( $object, $objectFunctionName ) )
00199 {
00200 $this->showResponse( $functionName, $namespaceURI,
00201 new eZSOAPFault( 'Server Error',
00202 'Objectmethod not found' ) );
00203 }
00204 else
00205 {
00206 $this->showResponse( $functionName, $namespaceURI,
00207 call_user_func_array( array( $object, $objectFunctionName ), $params ) );
00208 }
00209 }
00210 }
00211 else
00212 {
00213 $this->showResponse( $functionName, $namespaceURI,
00214 new eZSOAPFault( 'Server Error',
00215 'Method not found' ) );
00216 }
00217 }
00218 else
00219 {
00220
00221 $this->showResponse( $functionName, $namespaceURI,
00222 new eZSOAPFault( 'Server Error',
00223 '"Body" element in the request '.
00224 'has wrong number of children' ) );
00225
00226 }
00227 }
00228
00229
00230
00231
00232
00233
00234 function registerFunction( $name, $params=array() )
00235 {
00236 $this->FunctionList[] = $name;
00237 }
00238
00239
00240
00241
00242
00243
00244
00245 function stripHTTPHeader( $data )
00246 {
00247 $start = strpos( $data, "<?xml version=\"1.0\"?>" );
00248 return substr( $data, $start, strlen( $data ) - $start );
00249 }
00250
00251
00252 var $FunctionList;
00253
00254 var $RawPostData;
00255 }
00256
00257 ?>