1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
soapresponse.php
См. документацию.
1<?php
2
4{
6 var $Value = false;
7 var $ValueName = 0;
9 var $Type = false;
11 var $FaultString = false;
13 var $FaultCode = false;
15 var $IsFault = false;
17 var $Name;
20
22
24 var $DOMDocument = false;
25
26 public function __construct( $name="", $namespace="" )
27 {
28 $this->Name = $name;
29 $this->Namespace = $namespace;
30
31 // call the parents constructor
32 parent::__construct();
33 }
34
35 // Decodes the SOAP response stream
36 function decodeStream( $request, $stream )
37 {
38 global $APPLICATION;
39
40 $stream_cutted = $this->stripHTTPHeader( $stream );
41 if ( !$stream_cutted or !class_exists("CDataXML"))
42 {
43 $APPLICATION->ThrowException("Error: BitrixXMLParser. "
44 ."Downloaded page: <br>". htmlspecialcharsEx($stream));
45 return;
46 }
47
48 $stream = $stream_cutted;
49
50 $xml = new CDataXML();
51
52 if (!$xml->LoadString( $stream ))
53 {
54 $APPLICATION->ThrowException( "Error: Can't parse request xml data. ");
55 return;
56 }
57
58 $dom = $xml->GetTree();
59 $this->DOMDocument = $dom;
60 if ( get_class( $dom ) == "CDataXMLDocument" || get_class( $dom ) == "cdataxmldocument")
61 {
62 // check for fault
63 $response = $dom->elementsByName( 'Fault' );
64
65 if ( count( $response ) == 1 )
66 {
67 $this->IsFault = 1;
68 $faultStringArray = $dom->elementsByName( "faultstring" );
69 $this->FaultString = $faultStringArray[0]->textContent();
70
71 $faultCodeArray = $dom->elementsByName( "faultcode" );
72 $this->FaultCode = $faultCodeArray[0]->textContent();
73 return;
74 }
75
76 // get the response
77 $body = $dom->elementsByName( "Body" );
78 $body = $body[0];
79
80 if($body)
81 {
82 $response = $body->children();
84
85 if(get_class($response) == "CDataXMLNode" || get_class($response) == "cdataxmlnode")
86 {
87 /*Cut from the SOAP spec:
88 The method response is viewed as a single struct containing an accessor
89 for the return value and each [out] or [in/out] parameter.
90 The first accessor is the return value followed by the parameters
91 in the same order as in the method signature.
92
93 Each parameter accessor has a name corresponding to the name
94 of the parameter and type corresponding to the type of the parameter.
95 The name of the return value accessor is not significant.
96 Likewise, the name of the struct is not significant.
97 However, a convention is to name it after the method name
98 with the string "Response" appended.
99 */
100
101 $responseAccessors = $response->children();
102 //echo '<pre>'; print_r($responseAccessors); echo '</pre>';
103 if(count($responseAccessors) > 0)
104 {
105 $this->Value = array();
106 foreach($responseAccessors as $arChild)
107 {
108 $value = $arChild->decodeDataTypes();
109 $this->Value = array_merge($this->Value, $value);
110 }
111 }
112 }
113 else
114 {
115 $APPLICATION->ThrowException("Could not understand type of class decoded");
116 }
117 }
118 else
119 {
120 $APPLICATION->ThrowException("Wrong XML in response");
121 }
122 }
123 else
124 {
125 $APPLICATION->ThrowException( "Could not process XML in response" );
126 }
127 }
128
129 // Decodes a DOM node and returns the PHP datatype instance of it.
130 function decodeDataTypes( $node, $complexDataTypeName = "" )
131 {
132 global $xsd_simple_type;
133 $returnValue = false;
134
135 $attr = $node->getAttribute("type");
136 if ($attr and mb_strlen($attr))
137 {
138 return new CSOAPFault("Server Error", "Server supports only document/literal binding.");
139 }
140
141 $rootDataName = $this->Name;
142 if(trim($complexDataTypeName) <> '')
143 {
144 $rootDataName = trim($complexDataTypeName);
145 }
146
147 if (!$rootDataName or !isset($this->typensVars[$rootDataName]))
148 {
149 return new CSOAPFault("Server Error", "decodeDataTypes() can't find function type declaration." );
150 }
151
152 $name = $node->name();
153 $typeDeclaration = array();
154 $dataType = "";
155
156 /*
157 * Typen can be:
158 * 1) Whole Complex Data Type
159 * 2) Complex Data Type Part
160 * 3) Input decl
161 * 3) Output decl
162 */
163
164 if (isset($this->typensVars[$name]))
165 $typeDeclaration = $this->typensVars[$name];
166 if (isset($this->typensVars[$rootDataName][$name]))
167 $typeDeclaration = $this->typensVars[$rootDataName][$name];
168 else if (isset($this->typensVars[$rootDataName]["input"][$name]))
169 $typeDeclaration = $this->typensVars[$rootDataName]["input"][$name];
170 else if (isset($this->typensVars[$rootDataName]["output"][$name]))
171 $typeDeclaration = $this->typensVars[$rootDataName]["output"][$name];
172
173 if (!count($typeDeclaration))
174 {
175 return new CSOAPFault("Server Error", "decodeDataTypes() can't find type declaration for {$name} param." );
176 }
177 else
178 {
179 if (isset($typeDeclaration["varType"]))
180 $dataType = $typeDeclaration["varType"];
181 else
182 $dataType = $name; // case 1 of typens choose.
183 }
184
185 if (isset($xsd_simple_type[$dataType]))
186 $dataType = $xsd_simple_type[$dataType];
187
188 switch ( $dataType )
189 {
190 case "string" :
191 $returnValue = strval($node->textContent());
192 break;
193
194 case "integer" :
195 $returnValue = intval($node->textContent());
196 break;
197
198 case "float" :
199 case 'double' :
200 $returnValue = ($node->textContent());
201 break;
202
203 case "boolean" :
204 {
205 if ( $node->textContent() == "true" )
206 $returnValue = true;
207 else
208 $returnValue = false;
209 } break;
210
211 case "base64" :
212 case "base64Binary" :
213 $returnValue = base64_decode($node->textContent());
214
215 break;
216
217 case "any":
218 $returnValue = $node;
219 break;
220
221 default:
222 {
223 if (isset($typeDeclaration["arrType"]))
224 {
225 // Decode array
226
227 $maxOccurs = 0;
228 $returnValue = array();
229
230 $arrayType = $typeDeclaration["arrType"];
231 if (isset($typeDeclaration["maxOccursA"]))
232 $maxOccurs = $typeDeclaration["maxOccursA"];
233
234 if (isset($xsd_simple_type[$arrayType]))
235 {
236 $i = 0;
237 $childs = $node->children();
238 foreach ($childs as $child)
239 {
240 $i++;
241 $returnValue[] = $child->textContent();
242 if (intval($maxOccurs) and $i>intval($maxOccurs))
243 break;
244 }
245 }
246 else
247 {
248 foreach ($node->children() as $child)
249 {
250 /*
251 * Mega hack. Usually as name for this used
252 * ArrayOf{STRUCT|CLASS}El. So decoder must have
253 * a chance to find true data type = arrayType;
254 */
255 if (!isset($this->typensVars[$child->name]))
256 $child->name = $arrayType;
257 // Decode complex data type for an array
258 $decoded = $this->decodeDataTypes( $child, $arrayType );
259 if (is_object($decoded) and (get_class($decoded) == "CSOAPFault" or get_class($decoded) == "csoapfault"))
260 {
262 return;
263 }
264 $returnValue[] = $decoded;
265 }
266 }
267
268 break;
269 }
270 else
271 {
272 // Here we goes with struct, or with class
273 // First, try to find declaration
274 $objectDecl = 0;
275 $returnValue = array();
276 $params = array();
277
278 if (!isset($this->typensVars[$dataType])) break;
279 $objectDecl = $this->typensVars[$dataType];
280
281 // Type of serialization: class/assoc array
282 $objectClass = null;
283 $serialize = "assoc";
284 if (isset($objectDecl["serialize"]))
285 {
286 $serialize = $objectDecl["serialize"];
287 unset($objectDecl["serialize"]);
288 }
289
290 $requestParams = array(); // reorganize params
291 foreach ( $node->children() as $parameterNode )
292 {
293 if (!$parameterNode->name()) continue;
294 $requestParams[$parameterNode->name()] =
295 $parameterNode;
296 }
297
298 foreach($objectDecl as $pname => $param)
299 {
300 $decoded = null;
301
302 if (isset($requestParams[$pname]))
303 $decoded = $this->decodeDataTypes( $requestParams[$pname], $dataType );
304 if (is_object($decoded) and (get_class($decoded) == "CSOAPFault" or get_class($decoded) == "csoapfault"))
305 {
307 return;
308 }
309 if (!$decoded and (!isset($param["strict"]) or
310 (isset($param["strict"]) and $param["strict"] == "strict") ))
311 {
312 return new CSOAPFault("Server Error", "Request has not enough params of strict type to be decoded. " );
313 }
314
315 $params[$pname] = $decoded;
316 }
317
318 if ($serialize == "class")
319 {
320 $stillValid = true;
321 $classRequest = $params;
322 $params = null;
323
324 if (class_exists($dataType)) {
325 $objectClass = new $dataType;
326 if ($objectClass)
327 {
328 $existedVars = get_object_vars($objectClass);
329 foreach ($classRequest as $pname => $value)
330 {
331 if (!is_set($existedVars, $pname))
332 $stillValid = false;
333 $objectClass->$pname = $value;
334 }
335 }
336 else
337 {
338 $stillValid = false;
339 }
340 }
341
342 if ($stillValid) $params = $objectClass;
343 }
344
345 $returnValue = $params;
346 }
347
348
349 } break;
350 }
351
352 return $returnValue;
353 }
354
355 // Returns the XML payload for the response.
356 function payload( )
357 {
358 $root = new CXMLCreator("soap:Envelope");
359 $root->setAttribute("xmlns:soap", BX_SOAP_ENV);
360
361 // add the body
362 $body = new CXMLCreator( "soap:Body" );
363
364 // Check if it's a fault
365 if (is_object($this->Value) && mb_strtoupper(get_class($this->Value)) == 'CSOAPFAULT')
366 {
367 $fault = new CXMLCreator( "soap:Fault" );
368
369 $faultCodeNode = new CXMLCreator( "faultcode" );
370 $faultCodeNode->setData($this->Value->faultCode());
371
372 $fault->addChild( $faultCodeNode );
373
374 $faultStringNode = new CXMLCreator( "faultstring" );
375 $faultStringNode->setData( $this->Value->faultString() );
376
377 $fault->addChild( $faultStringNode );
378
379 if ($this->Value->detail)
380 $fault->addChild($this->Value->detail());
381
382 $body->addChild( $fault );
383 }
384 else
385 {
386 // add the request
387 $responseName = $this->Name . "Response";
388 $response = new CXMLCreator( $responseName );
389 $response->setAttribute("xmlns", $this->Namespace);
390 if (!isset($this->typensVars[$this->Name]["output"]) or !count($this->typensVars[$this->Name]["output"]))
391 {
392 if (count($this->typensVars))
393 {
394 $GLOBALS['APPLICATION']->ThrowException("payload() can't find output type declaration.", "SoapRespnose::payload()");
395 return;
396 }
397 else
398 {
399 //print_r($this->Value);
400 //die();
401 // EncodeLight
402 $value = CXMLCreator::encodeValueLight( $this->ValueName, $this->Value );
403 }
404
405 $response->addChild( $value );
406 }
407 else
408 {
409 //$return = new CXMLCreator($returnType);
410 $valueEncoder = new CSOAPCodec();
411 $valueEncoder->setTypensVars($this->typensVars);
412
413 foreach ($this->typensVars[$this->Name]["output"] as $returnType => $returnParam)
414 {
415 if (!$returnType)
416 {
417 $GLOBALS['APPLICATION']->ThrowException("payload() can't find output type declaration for {$this->Name}.", "SoapRespnose::payload()");
418 return;
419 }
420
421 $valueEncoder->setOutputVars($this->Name);
422
423 $value = $valueEncoder->encodeValue($returnType, isset($this->Value[$returnType]) ? $this->Value[$returnType] : $this->Value);
424
425 $response->addChild($value);
426 }
427
428 //AddM
429 }
430
431
432 $body->addChild( $response );
433 }
434
435 $root->addChild( $body );
436
437 //AddMessage2Log($root->getXML());
438 return CXMLCreator::getXMLHeader().$root->getXML();
439 }
440
441 // Strips the header information from the HTTP raw response.
443 {
444 $missingxml = false;
445 //$start = strpos( $data, "<"."?xml" );
446 $start = mb_strpos($data, "\r\n\r\n");
447 if ($start === false) return null;
448 $data = mb_substr($data, $start, mb_strlen($data) - $start);
449 return $data;
450 }
451
452 function value()
453 {
454 return $this->Value;
455 }
456
457 function setValue( $value )
458 {
459 $this->Value = $value;
460 }
461
462 function setValueName ( $valname )
463 {
464 $this->ValueName = $valname;
465 }
466
467 function isFault()
468 {
469 return $this->IsFault;
470 }
471
472 function faultCode()
473 {
474 return $this->FaultCode;
475 }
476
477 function faultString()
478 {
479 return $this->FaultString;
480 }
481
482 function setTypensVars($vars)
483 {
484 $this->typensVars = $vars;
485 }
486}
487
488?>
global $APPLICATION
Определения include.php:80
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
Определения xml.php:396
Определения soapcodec.php:4
Определения soapbase.php:40
Определения soapbase.php:83
Определения soapresponse.php:4
decodeDataTypes( $node, $complexDataTypeName="")
Определения soapresponse.php:130
faultString()
Определения soapresponse.php:477
payload()
Определения soapresponse.php:356
$FaultString
Contains fault string.
Определения soapresponse.php:11
$Namespace
Contains the target namespace for the response.
Определения soapresponse.php:19
$DOMDocument
Contains the DOM document for the current SOAP response.
Определения soapresponse.php:24
__construct( $name="", $namespace="")
Определения soapresponse.php:26
stripHTTPHeader( $data)
Определения soapresponse.php:442
$Value
Contains the response value.
Определения soapresponse.php:6
$ValueName
Определения soapresponse.php:7
$FaultCode
Contains the fault code.
Определения soapresponse.php:13
$IsFault
Contains true if the response was an fault.
Определения soapresponse.php:15
$Name
Contains the name of the response, i.e. function call name.
Определения soapresponse.php:17
isFault()
Определения soapresponse.php:467
$typensVars
Определения soapresponse.php:21
setTypensVars($vars)
Определения soapresponse.php:482
decodeStream( $request, $stream)
Определения soapresponse.php:36
setValue( $value)
Определения soapresponse.php:457
faultCode()
Определения soapresponse.php:472
$Type
Contains the response type.
Определения soapresponse.php:9
setValueName( $valname)
Определения soapresponse.php:462
value()
Определения soapresponse.php:452
static ShowSOAPFault($errorString)
Определения soapserver.php:304
Определения xmlcreator.php:3
static getXMLHeader()
Определения xmlcreator.php:198
static encodeValueLight( $name, $value)
Определения xmlcreator.php:67
$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
$requestParams
Определения urlrewrite.php:46
htmlspecialcharsEx($str)
Определения tools.php:2685
is_set($a, $k=false)
Определения tools.php:2133
$name
Определения menu_edit.php:35
$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
$GLOBALS['_____370096793']
Определения update_client.php:1