1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
soapcodec.php
См. документацию.
1<?php
2
4{
7
8 public function __construct()
9 {
10 }
11
12 function setTypensVars($vars)
13 {
14 $this->typensVars = $vars;
15 }
16
17 function setOutputVars($functionName)
18 {
19 if (!isset($this->typensVars[$functionName]["output"]))
20 {
21 ShowError("encodeValue() cant find output declaration.");
22 exit();
23 }
24
25 $this->outputVars = $this->typensVars[$functionName]["output"];
26 }
27
28 function _validateSimpleType($dataType, $value)
29 {
30 global $xsd_simple_type;
31 if (!isset($xsd_simple_type[$dataType]))
32 CSOAPCodec::_errorTypeValidation("[Is not a simple type.{$dataType}]", $value);
33
34 if ($dataType != gettype( $value ))
35 {
36 // all numbers are same as string
37 if (is_numeric($value) and (
38 $dataType == "integer" or
39 $dataType == "double" or
40 $dataType == "float"))
41 return;
42 //elseif ($dataType == 'base64Binary' && preg_match('/^([A-Za-z0-9]|\+|\/|\-|\=)+$/', $value))
43 elseif ($dataType == 'base64Binary' || $dataType == 'any')
44 return;
45
46 CSOAPCodec::_errorTypeValidation($dataType, $value);
47 }
48 }
49
50 function _validateClassType($classType, $value)
51 {
52 $phpClassType = mb_strtolower($classType);
53 $phpValue = mb_strtolower(get_class($value));
54 if ($phpClassType != $phpValue)
55 {
56 CSOAPServer::ShowSOAPFault("_errorTypeValidation(): Type validation for func. failed: {$classType} != ".get_class($value));
57 exit();
58 }
59 }
60
61 function _validateType($dataType, $value)
62 {
63 global $xsd_simple_type;
64 if (isset($xsd_simple_type[$dataType]))
65 {
66 /*
67 if (is_array($value))
68 {
69 echo $dataType;
70 die();
71
72 }
73 else*/if ($dataType != gettype( $value ))
74 {
75 // all numbers are same as string
76 if (is_numeric($value) and (
77 $dataType == "integer" or
78 $dataType == "double" or
79 $dataType == "float"))
80 return;
81 //elseif ($dataType == 'base64Binary' && preg_match('/^([A-Za-z0-9]|\+|\/|\-|\=)+$/', $value))
82 elseif ($dataType == 'base64Binary' || $dataType == 'any')
83 return;
84
85 CSOAPCodec::_errorTypeValidation($dataType, $value);
86 }
87 }
88 else
89 {
90 if (!is_object($value) and !is_array($value))
91 CSOAPCodec::_errorTypeValidation($dataType, $value);
92 }
93 }
94
95 function _errorTypeValidation($dataType, $value)
96 {
97 CSOAPServer::ShowSOAPFault("_errorTypeValidation(): Type validation for func. failed: {$dataType} != ".gettype($value));
98 exit();
99 }
100
101 // Encodes a PHP variable into a SOAP datatype.
102 function encodeValue($name, $value, $complexDataTypeName = "")
103 {
104 global $xsd_simple_type;
105 if (!is_array($this->outputVars) or !count($this->outputVars))
106 {
107 CSOAPServer::ShowSOAPFault("encodeValue() has no Output Data Type Declaration for validation.");
108 exit();
109 }
110
111 $dataType = "";
112 $typeDeclaration = "";
113 if (isset($this->outputVars[$name]))
114 $typeDeclaration = $this->outputVars[$name];
115 else if (isset($this->typensVars[$name]))
116 $typeDeclaration = $this->typensVars[$name];
117 else if (isset($this->typensVars[$complexDataTypeName][$name]))
118 $typeDeclaration = $this->typensVars[$complexDataTypeName][$name];
119
120 if (isset($typeDeclaration["varType"])) // if not, name = complex data type
121 $dataType = $typeDeclaration["varType"];
122 else
123 $dataType = $name;
124
125 if (isset($xsd_simple_type[$dataType]))
126 $dataType = $xsd_simple_type[$dataType];
127
128 // Type validation
129 $this->_validateType($dataType, $value);
130
131 switch ($dataType)
132 {
133 case "string" :
134 {
135 $node = new CXMLCreator( $name );
136 //$node->setAttribute( "type", BX_SOAP_XSD_PREFIX . ":string" );
137 $node->setData($value);
138 return $node;
139 } break;
140
141 case "boolean" :
142 {
143 $node = new CXMLCreator( $name );
144 //$node->setAttribute( "type", BX_SOAP_XSD_PREFIX . ":boolean" );
145 if ( $value === true )
146 $node->setData( "true" );
147 else
148 $node->setData( "false" );
149 return $node;
150 } break;
151
152 case "integer" :
153 {
154 $node = new CXMLCreator( $name );
155 //$node->setAttribute( "type", BX_SOAP_XSD_PREFIX . ":int" );
156 $node->setData( intval($value) );
157 return $node;
158 } break;
159
160 case "float":
161 case "double" :
162 {
163 $node = new CXMLCreator( $name );
164 //$node->setAttribute( "type", BX_SOAP_XSD_PREFIX . ":float" );
165 $node->setData($value);
166 return $node;
167 } break;
168
169 // added by Sigurd
170 case "base64":
171 case "base64Binary":
172 $node = new CXMLCreator($name);
173 //$node->setAttribute("type", BX_SOAP_XSD_PREFIX . ":base64Binary" );
174 $node->setData(base64_encode($value));
175 return $node;
176
177 break;
178
179 case 'any':
180 $node = new CXMLCreator($name);
181
182 if (is_object($value))
183 {
184 if (get_class($value) == 'CDataXML')
185 $node->addChild(CXMLCreator::CreateFromDOM($value->GetTree()));
186 elseif (get_class($value) == 'CDataXMLDocument')
187 $node->addChild(CXMLCreator::CreateFromDOM($value));
188 elseif(get_class($value) == 'CXMLCreator')
189 $node->addChild($value);
190 }
191 else
192 {
193 $data = new CDataXML();
194 if ($data->LoadString($value))
195 $node->addChild(CXMLCreator::CreateFromDOM($data->GetTree()));
196 else
197 $node->setData($value);
198 }
199
200 return $node;
201 break;
202
203 default :
204 {
205 $node = new CXMLCreator( $name );
206
207 if (isset($typeDeclaration["arrType"]))
208 {
209 if (!isset($typeDeclaration["varType"]))
210 $this->_errorTypeValidation("varType [undef]", $value);
211
212 $varType = $typeDeclaration["varType"];
213
214 // Decode array
215 $maxOccurs = 0;
216
217 $arrayType = $typeDeclaration["arrType"];
218 if (isset($typeDeclaration["maxOccursA"]))
219 $maxOccurs = $typeDeclaration["maxOccursA"];
220
221 if (isset($xsd_simple_type[$arrayType]))
222 {
223 $i = 0;
224 $arrayType = $xsd_simple_type[$arrayType];
225 $arrayTypeEl = $varType."El"; // TODO: non fixed. get El name from wsdl. or decl.
226 if (!is_array($value))
227 CSOAPCodec::_errorTypeValidation("Array", $value);
228
229 foreach ($value as $valnode)
230 {
231 $i++;
232 $this->_validateType($arrayType, $valnode);
233 $cndata = new CXMLCreator ( $arrayTypeEl );
234 $cndata->setData($valnode);
235 $node->addChild($cndata);
236
237 if (intval($maxOccurs)>0 and $i>$maxOccurs)
238 break;
239 }
240 }
241 else
242 {
243 // Complex data type arrays // $arrayType as is.
244 // TODO: non fixed. get $arrayTypeEl name from wsdl. or decl.
245 $i = 0;
246 $arrayTypeEl = $varType."El";
247 if (!is_array($value))
248 CSOAPCodec::_errorTypeValidation("Array", $value);
249
250 foreach ($value as $valnode)
251 {
252 $decoded = null;
253 $i++;
254
255 $this->_validateType($arrayType, $valnode);
256 $decoded = $this->encodeValue( $arrayType, $valnode );
257
258 $cndata = new CXMLCreator ( $arrayTypeEl );
259
260 if ($decoded)
261 {
262 $this->_validateClassType("CXMLCreator", $decoded);
263 $decoded->setName($arrayTypeEl);
264 $node->addChild($decoded);
265 }
266
267 if (intval($maxOccurs)>0 and $i>$maxOccurs)
268 break;
269 }
270 }
271 }
272 else
273 {
274 // Here we goes with struct, or with class
275 // First, try to find declaration
276
277 $objectDecl = 0;
278 $returnValue = array();
279 $params = array();
280
281 if (!isset($this->typensVars[$dataType])) break;
282 $objectDecl = $this->typensVars[$dataType];
283
284 if (!$objectDecl)
285 {
286 CSOAPServer::ShowSOAPFault("encodeValue() cant find complex type declaration for {$dataType}.");
287 exit();
288 }
289
290 // Type of serialization: class/assoc array
291 $objectClass = null;
292 $serialize = "assoc";
293 if (isset($objectDecl["serialize"]))
294 {
295 $serialize = $objectDecl["serialize"];
296 unset($objectDecl["serialize"]);
297 }
298
299 // Validate hard complex data types
300 if ($serialize == "assoc")
301 $this->_validateType("array", $value);
302 if ($serialize != "assoc")
303 $this->_validateClassType($dataType, $value);
304
305 foreach($objectDecl as $pname => $param)
306 {
307 $decoded = null;
308 $strict = true;
309 if (isset($param["strict"])) $strict = ($param["strict"]=="strict")?true:false;
310
311 if ($serialize == "assoc")
312 {
313 //var_dump($pname); var_dump($value[$pname]); die();
314 if (isset($value[$pname]))
315 $decoded = $this->encodeValue( $pname, $value[$pname], $dataType );
316 }
317 else
318 if ($serialize != "assoc")
319 {
320 if (isset($value->$pname))
321 $decoded = $this->encodeValue( $pname, $value->$pname, $dataType );
322 }
323
324
325 if ($decoded)
326 $this->_validateClassType("CXMLCreator", $decoded);
327
328 if (!$decoded and $strict)
329 {
330 CSOAPServer::ShowSOAPFault("Request has not enough params of strict type to be decoded. ");
331 exit();
332 }
333
334 $node->addChild($decoded);
335 }
336 }
337 return $node;
338 } break;
339 }
340
341 return false;
342 }
343}
344
345?>
Определения xml.php:396
Определения soapcodec.php:4
__construct()
Определения soapcodec.php:8
_validateSimpleType($dataType, $value)
Определения soapcodec.php:28
setOutputVars($functionName)
Определения soapcodec.php:17
_validateType($dataType, $value)
Определения soapcodec.php:61
$outputVars
Определения soapcodec.php:5
encodeValue($name, $value, $complexDataTypeName="")
Определения soapcodec.php:102
$typensVars
Определения soapcodec.php:6
setTypensVars($vars)
Определения soapcodec.php:12
_errorTypeValidation($dataType, $value)
Определения soapcodec.php:95
_validateClassType($classType, $value)
Определения soapcodec.php:50
static ShowSOAPFault($errorString)
Определения soapserver.php:304
Определения xmlcreator.php:3
static CreateFromDOM($dom)
Определения xmlcreator.php:208
$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
ShowError($strError, $cls="errortext")
Определения tools.php:4499
$name
Определения menu_edit.php:35
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$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