1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
soapserver.php
См. документацию.
1<?php
2
4{
5 function OnBeforeRequest(&$cserver)
6 {
7 }
8
9 /* $cserver->RawPostData */
10 function OnAfterResponse(&$cserver)
11 {
12 }
13
14 /*
15 * If function returns true, chain of ProcessRequest ends.
16 * If function returns true, this means function already passed It's value to ShowResponse handler
17 * If returns false, then next item in a chain will be called.
18 * Result Value must be set to $cserver->ResponseValue
19 */
20 function ProcessRequestHeader(&$cserver, $header)
21 {
22 }
23
24 /* stub, never used */
25 function ProcessRequestBody(&$cserver, $body)
26 {
27 }
28}
29
31{
32 /*
33 * typename => name => array()
34 * funcname => parameters => array()
35 * Array can contain:
36 * serialize => class/assoc array.
37 * varType, arrType
38 * */
40
43
46
48 {
49 $this->FunctionList[] = $name;
50 $this->TypensVars[$name] = $params;
51
52 if ($params["request"]) $this->MessageTags[$params["request"]] = $name;
53 if ($params["response"]) $this->MessageTags[$params["response"]] = $name;
54 }
55
56 /*
57 * $complex = array( "typename" => array( paraname => array(type desc, valType)))
58 */
59 function RegisterComplexType($complex)
60 {
61 foreach ($complex as $complexTypeName => $declaration)
62 {
63 $this->TypensVars[$complexTypeName] = $declaration;
64 }
65 }
66
67 function ProcessRequestBody(&$cserver, $body)
68 {
69 $functionName = $body->name();
70 $namespaceURI = $body->namespaceURI();
71 $requestNode = $body;
72
73 // If this is request name in functionName, get functionName.
74 if (!in_array($functionName, $this->FunctionList)
75 and isset($this->MessageTags[$functionName])
76 )
77 {
78 $functionName = $this->MessageTags[$functionName];
79 }
80
81 if (!in_array($functionName, $this->FunctionList))
82 {
83 CSOAPServer::ShowSOAPFault("Trying to access unregistered function: ".$functionName);
84 return true;
85 }
86
87 $objectName = "";
88 $params = array();
89
90 $paramsDecoder = new CSOAPResponse($functionName, $namespaceURI);
91 $paramsDecoder->setTypensVars($this->TypensVars);
92
93 if (!isset($this->TypensVars[$functionName]) or
94 !isset($this->TypensVars[$functionName]["myclassname"]) or
95 !isset($this->TypensVars[$functionName]["input"])
96 )
97 {
98 CSOAPServer::ShowSOAPFault("Requested function has no type specified: ".$functionName);
99 return true;
100 }
101
102 $objectName = $this->TypensVars[$functionName]["myclassname"];
103 $inputParams = $this->TypensVars[$functionName]["input"];
104
105 $httpAuth = "N";
106 if (isset($this->TypensVars[$functionName]["httpauth"]))
107 {
108 $httpAuth = $this->TypensVars[$functionName]["httpauth"];
109 }
110
111 if ($httpAuth == "Y" and !CWebService::MethodRequireHTTPAuth($objectName, $functionName))
112 {
113 CSOAPServer::ShowSOAPFault("Requested function requires HTTP Basic Auth to be done before.");
114 return true;
115 }
116
117 $requestParams = array(); // reorganize params
118 foreach ($requestNode->children() as $parameterNode)
119 {
120 if (!$parameterNode->name())
121 continue;
122 $requestParams[$parameterNode->name()] = $parameterNode;
123 }
124
125 // check parameters/decode // check strict params
126 foreach ($inputParams as $pname => $param)
127 {
128 $decoded = null;
129
130 if (isset($requestParams[$pname]))
131 {
132 $decoded = $paramsDecoder->decodeDataTypes($requestParams[$pname]);
133 }
134
135 if (is_object($decoded) and (get_class($decoded) == "CSOAPFault" or get_class($decoded) == "csoapfault"))
136 {
138 return true;
139 }
140
141 if (
142 !isset($decoded) and (!isset($param["strict"])
143 or (isset($param["strict"]) and $param["strict"] == "strict"))
144 )
145 {
146 CSOAPServer::ShowSOAPFault("Request has not enough params of strict type to be decoded. ");
147 return true;
148 }
149 $params[] = $decoded;
150 }
151
152 unset($paramsDecoder);
153
154 $object = null;
155
156 if (class_exists($objectName))
157 $object = new $objectName;
158
159 if (is_object($object) && method_exists($object, $functionName))
160 {
161 $this->ShowResponse(
162 $cserver,
163 $functionName,
164 $namespaceURI,
165 call_user_func_array(
166 array($object, $functionName),
167 $params
168 )
169 );
170 }
171 else if (!class_exists($objectName))
172 {
173 $this->ShowResponse(
174 $cserver,
175 $functionName,
176 $namespaceURI,
177 new CSOAPFault('Server Error', 'Object not found')
178 );
179 }
180 else
181 {
182 $this->ShowResponse(
183 $cserver,
184 $functionName,
185 $namespaceURI,
186 new CSOAPFault('Server Error', 'Method not found')
187 );
188 }
189
190 return true;
191 }
192
193 function ShowResponse(&$cserver, $functionName, $namespaceURI, &$value)
194 {
195 global $APPLICATION;
196 // Convert input data to XML
197
198 $response = new CSOAPResponse($functionName, $namespaceURI);
199 $response->setTypensVars($this->TypensVars);
200
201 $response->setValue($value);
202
203 $payload = $response->payload();
204
205 header("SOAPServer: BITRIX SOAP");
206 header("Content-Type: text/xml; charset=\"UTF-8\"");
207 header("Content-Length: " . strlen($payload));
208
209 $APPLICATION->RestartBuffer();
210 $cserver->RawPayloadData = $payload;
211 echo $payload;
212 }
213}
214
216{
220
223
224 public function __construct()
225 {
226 $this->RawPostData = file_get_contents("php://input");
227 }
228
229 function GetRequestData()
230 {
231 return $this->RawPostData;
232 }
233
235 {
237 }
238
239 function AddServerResponser(&$respobject)
240 {
241 if (is_subclass_of($respobject, "CSOAPServerResponser"))
242 {
243 $this->OnRequestEvent[count($this->OnRequestEvent)] =& $respobject;
244 return true;
245 }
246
247 return false;
248 }
249
250 // $valueEncoded type of CXMLCreator
251 function ShowRawResponse($valueEncoded, $wrapEnvelope = false)
252 {
253 global $APPLICATION;
254
255 if ($wrapEnvelope)
256 {
257 // $valueEncoded class of CXMLCreator
258 $root = new CXMLCreator("soap:Envelope");
259 $root->setAttribute("xmlns:soap", BX_SOAP_ENV);
260
261 // add the body
262 $body = new CXMLCreator("soap:Body");
263
264 $body->addChild($valueEncoded);
265
266 $root->addChild($body);
267
268 $valueEncoded = $root;
269 }
270
271 $payload = CXMLCreator::getXMLHeader().$valueEncoded->getXML();
272
273 header("SOAPServer: BITRIX SOAP");
274 header("Content-Type: text/xml; charset=\"UTF-8\"");
275 header("Content-Length: " . strlen($payload));
276
277 $APPLICATION->RestartBuffer();
278 $this->RawPayloadData = $payload;
279
280 echo $payload;
281 }
282
283 function ShowResponse($functionName, $namespaceURI, $valueName, &$value)
284 {
285 global $APPLICATION;
286 // Convert input data to XML
287
288 $response = new CSOAPResponse($functionName, $namespaceURI);
289 $response->setValueName($valueName);
290 $response->setValue($value);
291
292 $payload = $response->payload();
293
294 header("SOAPServer: BITRIX SOAP");
295 header("Content-Type: text/xml; charset=\"UTF-8\"");
296 header("Content-Length: " . strlen($payload));
297
298 $APPLICATION->RestartBuffer();
299
300 $this->RawPayloadData = $payload;
301 echo $payload;
302 }
303
304 public static function ShowSOAPFault($errorString)
305 {
306 global $APPLICATION;
307 $response = new CSOAPResponse('unknown_function_name', 'unknown_namespace_uri');
308 if (is_object($errorString) and (get_class($errorString) == "CSOAPFault" or get_class($errorString) == "csoapfault"))
309 $response->setValue($errorString /*CSOAPFault*/);
310 else
311 $response->setValue(new CSOAPFault('Server Error', $errorString));
312
313 $payload = $response->payload();
314
315 header("SOAPServer: BITRIX SOAP");
316 header("Content-Type: text/xml; charset=\"UTF-8\"");
317 header("Content-Length: " . strlen($payload));
318
319 $APPLICATION->RestartBuffer();
320 echo $payload;
321
322 die();
323 }
324
329 function ProcessRequest()
330 {
331 if (
332 $_SERVER["REQUEST_METHOD"] != "POST"
333 ||!class_exists("CDataXML")
334 )
335 {
336 $this->ShowSOAPFault("Error: this web page does only understand POST methods. BitrixXMLParser. ");
337 }
338
339 for ($i = 0; $i < count($this->OnRequestEvent); $i++)
340 {
341 $this->OnRequestEvent[$i]->OnBeforeRequest($this);
342 }
343
344 //AddMessage2Log($this->RawPostData);
345 $xmlData = $this->stripHTTPHeader($this->RawPostData);
346
347 $xml = new CDataXML();
348
349 //AddMessage2Log($xmlData);
350 if (!$xml->LoadString($xmlData))
351 {
352 $this->ShowSOAPFault("Error: Can't parse request xml data. ");
353 }
354
355 $dom = $xml->GetTree();
356
357 // Check for non-parsing XML, to avoid call to non-object error.
358 if (!is_object($dom))
359 {
360 $this->ShowSOAPFault("Bad XML");
361 }
362
363 // add namespace fetching on body
364 // get the SOAP body
365 $body = $dom->elementsByName("Body");
366
367 if(count($body) <= 0)
368 {
369 $this->ShowSOAPFault('No "Body" element in the request');
370 }
371 else
372 {
373 $children = $body[0]->children();
374
375 if(count($children) == 1)
376 {
377 $requestNode = $children[0];
378 $requestParsed = false;
379
380 // get target namespace for request
381 // it often function request message. in wsdl gen. = function+"request"
382 $functionName = $requestNode->name();
383 $namespaceURI = $requestNode->namespaceURI();
384
385 for($i = 0; $i < count($this->OnRequestEvent); $i++)
386 {
387 if($this->OnRequestEvent[$i]->ProcessRequestBody($this, $requestNode))
388 {
389 $requestParsed = true;
390 break;
391 }
392 }
393
394 for($i = 0; $i < count($this->OnRequestEvent); $i++)
395 {
396 $this->OnRequestEvent[$i]->OnAfterResponse($this);
397 }
398
399 if(!$requestParsed)
400 {
401 $this->ShowSOAPFault('Unknown operation requested.');
402 }
403
404 return $requestParsed;
405 }
406 else
407 {
408 $this->ShowSOAPFault('"Body" element in the request has wrong number of children');
409 }
410 }
411
412 return false;
413 }
414
416 {
417 //$start = strpos( $data, "<"."?xml" );
418 $start = mb_strpos($data, "\r\n\r\n");
419 return mb_substr($data, $start, mb_strlen($data) - $start);
420 }
421}
global $APPLICATION
Определения include.php:80
Определения xml.php:396
Определения soapbase.php:83
Определения soapresponse.php:4
Определения soapserver.php:216
$OnRequestEvent
Consists of instances of CSOAPServerResponser.
Определения soapserver.php:222
__construct()
Определения soapserver.php:224
$RawPostData
Contains the RAW HTTP post data information.
Определения soapserver.php:218
GetResponseData()
Определения soapserver.php:234
stripHTTPHeader($data)
Определения soapserver.php:415
ProcessRequest()
Определения soapserver.php:329
$RawPayloadData
Определения soapserver.php:219
ShowRawResponse($valueEncoded, $wrapEnvelope=false)
Определения soapserver.php:251
AddServerResponser(&$respobject)
Определения soapserver.php:239
GetRequestData()
Определения soapserver.php:229
ShowResponse($functionName, $namespaceURI, $valueName, &$value)
Определения soapserver.php:283
static ShowSOAPFault($errorString)
Определения soapserver.php:304
OnAfterResponse(&$cserver)
Определения soapserver.php:10
OnBeforeRequest(&$cserver)
Определения soapserver.php:5
ProcessRequestHeader(&$cserver, $header)
Определения soapserver.php:20
ProcessRequestBody(&$cserver, $body)
Определения soapserver.php:25
Определения soapserver.php:31
$MessageTags
message => function
Определения soapserver.php:42
$FunctionList
Contains a list over registered functions.
Определения soapserver.php:45
$TypensVars
Определения soapserver.php:39
ShowResponse(&$cserver, $functionName, $namespaceURI, &$value)
Определения soapserver.php:193
RegisterFunction($name, $params=array())
Определения soapserver.php:47
ProcessRequestBody(&$cserver, $body)
Определения soapserver.php:67
RegisterComplexType($complex)
Определения soapserver.php:59
static MethodRequireHTTPAuth($class, $method)
Определения webservice.php:204
Определения xmlcreator.php:3
static getXMLHeader()
Определения xmlcreator.php:198
$children
Определения sync.php:12
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$start
Определения get_search.php:9
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
$requestParams
Определения urlrewrite.php:46
$name
Определения menu_edit.php:35
die
Определения quickway.php:367
$i
Определения factura.php:643
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$response
Определения result.php:21
const BX_SOAP_ENV
Определения soapbase.php:3