forked from mikaelcom/WsdlToPhp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WsdlClassFileTpl.php
603 lines (603 loc) · 15.8 KB
/
WsdlClassFileTpl.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
<?php
/**
* File for PackageNameWsdlClass to communicate with SOAP service
* @package PackageName
* @date generation_date
*/
/**
* File for PackageNameWsdlClass to communicate with SOAP service
* meta_informations
* @package PackageName
* @date generation_date
*/
class PackageNameWsdlClass extends stdClass implements ArrayAccess,Iterator,Countable
{
/**
* Option key to define WSDL url
* @var string
*/
const WSDL_URL = 'wsdl_url';
/**
* Option key to define WSDL login
* @var string
*/
const WSDL_LOGIN = 'wsdl_login';
/**
* Option key to define WSDL password
* @var string
*/
const WSDL_PASSWD = 'wsdl_password';
/**
* Option key to define WSDL trace option
* @var string
*/
const WSDL_TRACE = 'wsdl_trace';
/**
* Option key to define WSDL exceptions
* @var string
*/
const WSDL_EXCPTS = 'wsdl_exceptions';
/**
* Option key to define WSDL cache_wsdl
* @var string
*/
const WSDL_CACHE_WSDL = 'wsdl_cache_wsdl';
/**
* Option key to define WSDL stream_context
* @var string
*/
const WSDL_STREAM_CONTEXT = 'wsdl_stream_context';
/**
* Option key to define WSDL soap_version
* @var string
*/
const WSDL_SOAP_VERSION = 'wsdl_soap_version';
/**
* Option key to define WSDL compression
* @var string
*/
const WSDL_COMPRESSION = 'wsdl_compression';
/**
* Option key to define WSDL encoding
* @var string
*/
const WSDL_ENCODING = 'wsdl_encoding';
/**
* Option key to define WSDL connection_timeout
* @var string
*/
const WSDL_CONNECTION_TIMEOUT = 'wsdl_connection_timeout';
/**
* Option key to define WSDL typemap
* @var string
*/
const WSDL_TYPEMAP = 'wsdl_typemap';
/**
* Option key to define WSDL user_agent
* @var string
*/
const WSDL_USER_AGENT = 'wsdl_user_agent';
/**
* Option key to define WSDL features
* @var string
*/
const WSDL_FEATURES = 'wsdl_features';
/**
* Option key to define WSDL keep_alive
* @var string
*/
const WSDL_FKEEP_ALIVE = 'wsdl_keep_alive';
/**
* Soapclient called to communicate with the actual SOAP Service
* @var SoapClient
*/
private static $soapClient;
/**
* Contains Soap call result
* @var mixed
*/
private $result;
/**
* Contains last errors
* @var array
*/
private $lastError;
/**
* Array that contains values when only one parameter is set when calling __construct method
* @var array
*/
private $internArrayToIterate;
/**
* Bool that tells if array is set or not
* @var bool
*/
private $internArrayToIterateIsArray;
/**
* Items index browser
* @var int
*/
private $internArrayToIterateOffset;
/**
* Constructor
* @uses PackageNameWsdlClass::setLastError()
* @uses PackageNameWsdlClass::initSoapClient()
* @uses PackageNameWsdlClass::initInternArrayToIterate()
* @uses PackageNameWsdlClass::_set()
* @param array $_arrayOfValues values
* @return PackageNameWsdlClass
*/
public function __construct($_arrayOfValues = array())
{
$this->setLastError(array());
/**
* Init soap Client
* Set default values
*/
$this->initSoapClient($_arrayOfValues);
/**
* Init array of values if set
*/
$this->initInternArrayToIterate($_arrayOfValues);
/**
* Generic set methods
*/
if(is_array($_arrayOfValues) && count($_arrayOfValues))
{
foreach($_arrayOfValues as $name=>$value)
$this->_set($name,$value);
}
}
/**
* Static method getting current SoapClient
* @return SoapClient
*/
public static function getSoapClient()
{
return self::$soapClient;
}
/**
* Static method setting current SoapClient
* @param SoapClient $_soapClient
* @return SoapClient
*/
protected static function setSoapClient(SoapClient $_soapClient)
{
return (self::$soapClient = $_soapClient);
}
/**
* Method initiating SoapClient
* @uses PackageNameWsdlClass::classMap()
* @uses PackageNameWsdlClass::getDefaultWsdlOptions()
* @uses PackageNameWsdlClass::setSoapClient()
* @param array $_wsdlOptions WSDL options
* @return void
*/
public function initSoapClient($_wsdlOptions)
{
if(class_exists('PackageNameClassMap',true))
{
$wsdlOptions = array();
$wsdlOptions['classmap'] = PackageNameClassMap::classMap();
$defaultWsdlOptions = self::getDefaultWsdlOptions();
foreach($defaultWsdlOptions as $optioName=>$optionValue)
{
if(array_key_exists($optioName,$_wsdlOptions) && !empty($_wsdlOptions[$optioName]))
$wsdlOptions[str_replace('wsdl_','',$optioName)] = $_wsdlOptions[$optioName];
elseif(!empty($optionValue))
$wsdlOptions[str_replace('wsdl_','',$optioName)] = $optionValue;
}
if(array_key_exists(str_replace('wsdl_','',self::WSDL_URL),$wsdlOptions))
{
$wsdlUrl = $wsdlOptions[str_replace('wsdl_','',self::WSDL_URL)];
unset($wsdlOptions[str_replace('wsdl_','',self::WSDL_URL)]);
self::setSoapClient(new SoapClient($wsdlUrl,$wsdlOptions));
}
}
}
/**
* Method returning all default options values
* @uses PackageNameWsdlClass::WSDL_CACHE_WSDL
* @uses PackageNameWsdlClass::WSDL_COMPRESSION
* @uses PackageNameWsdlClass::WSDL_CONNECTION_TIMEOUT
* @uses PackageNameWsdlClass::WSDL_ENCODING
* @uses PackageNameWsdlClass::WSDL_EXCPTS
* @uses PackageNameWsdlClass::WSDL_FEATURES
* @uses PackageNameWsdlClass::WSDL_LOGIN
* @uses PackageNameWsdlClass::WSDL_PASSWD
* @uses PackageNameWsdlClass::WSDL_SOAP_VERSION
* @uses PackageNameWsdlClass::WSDL_STREAM_CONTEXT
* @uses PackageNameWsdlClass::WSDL_TRACE
* @uses PackageNameWsdlClass::WSDL_TYPEMAP
* @uses PackageNameWsdlClass::WSDL_URL
* @uses PackageNameWsdlClass::WSDL_USER_AGENT
* @return array
*/
public static function getDefaultWsdlOptions()
{
return array(
self::WSDL_CACHE_WSDL=>WSDL_CACHE_NONE,
self::WSDL_COMPRESSION=>null,
self::WSDL_CONNECTION_TIMEOUT=>null,
self::WSDL_ENCODING=>null,
self::WSDL_EXCPTS=>true,
self::WSDL_FEATURES=>null,
self::WSDL_LOGIN=>null,
self::WSDL_PASSWD=>null,
self::WSDL_SOAP_VERSION=>null,
self::WSDL_STREAM_CONTEXT=>null,
self::WSDL_TRACE=>true,
self::WSDL_TYPEMAP=>null,
self::WSDL_URL=>null,
self::WSDL_USER_AGENT=>null);
}
/**
* Method alias to count
* @uses PackageNameWsdlClass::count()
* @return int
*/
public function length()
{
return $this->count();
}
/**
* Method returning item length, alias to length
* @uses PackageNameWsdlClass::internArrayToIterateIsArray()
* @uses PackageNameWsdlClass::getInternArrayToIterate()
* @return int
*/
public function count()
{
return $this->getInternArrayToIterateIsArray()?count($this->getInternArrayToIterate()):-1;
}
/**
* Method returning the current element
* @uses PackageNameWsdlClass::offsetGet()
* @return mixed
*/
public function current()
{
return $this->offsetGet($this->internArrayToIterateOffset);
}
/**
* Method moving the current position to the next element
* @uses PackageNameWsdlClass::getInternArrayToIterateOffset()
* @uses PackageNameWsdlClass::setInternArrayToIterateOffset()
* @return int
*/
public function next()
{
return $this->setInternArrayToIterateOffset($this->getInternArrayToIterateOffset() + 1);
}
/**
* Method resetting itemOffset
* @uses PackageNameWsdlClass::setInternArrayToIterateOffset()
* @return int
*/
public function rewind()
{
return $this->setInternArrayToIterateOffset(0);
}
/**
* Method checking if current itemOffset points to an existing item
* @uses PackageNameWsdlClass::getInternArrayToIterateOffset()
* @uses PackageNameWsdlClass::offsetExists()
* @return bool true|false
*/
public function valid()
{
return $this->offsetExists($this->getInternArrayToIterateOffset());
}
/**
* Method returning current itemOffset value, alias to getInternArrayToIterateOffset
* @uses PackageNameWsdlClass::getInternArrayToIterateOffset()
* @return int
*/
public function key()
{
return $this->getInternArrayToIterateOffset();
}
/**
* Method alias to offsetGet
* @see PackageNameWsdlClass::offsetGet()
* @uses PackageNameWsdlClass::offsetGet()
* @param int $_index
* @return mixed
*/
public function item($_index)
{
return $this->offsetGet($_index);
}
/**
* Default method adding item to array
* @uses PackageNameWsdlClass::getAttributeName()
* @uses PackageNameWsdlClass::__toString()
* @uses PackageNameWsdlClass::_set()
* @uses PackageNameWsdlClass::_get()
* @uses PackageNameWsdlClass::setInternArrayToIterate()
* @uses PackageNameWsdlClass::setInternArrayToIterateIsArray()
* @uses PackageNameWsdlClass::setInternArrayToIterateOffset()
* @param mixed $_item value
* @return bool true|false
*/
public function add($_item)
{
if($this->getAttributeName() != '' && stripos($this->__toString(),'array') !== false)
{
/**
* init array
*/
if(!is_array($this->_get($this->getAttributeName())))
$this->_set($this->getAttributeName(),array());
/**
* current array
*/
$currentArray = $this->_get($this->getAttributeName());
array_push($currentArray,$_item);
$this->_set($this->getAttributeName(),$currentArray);
$this->setInternArrayToIterate($currentArray);
$this->setInternArrayToIterateIsArray(true);
$this->setInternArrayToIterateOffset(0);
return true;
}
return false;
}
/**
* Method to call when sending data to request for *array* type class
* @uses PackageNameWsdlClass::getAttributeName()
* @uses PackageNameWsdlClass::__toString()
* @uses PackageNameWsdlClass::_get()
* @return mixed
*/
public function toSend()
{
if($this->getAttributeName() != '' && stripos($this->__toString(),'array') !== false)
return $this->_get($this->getAttributeName());
else
return null;
}
/**
* Method returning the first item
* @uses PackageNameWsdlClass::item()
* @return mixed
*/
public function first()
{
return $this->item(0);
}
/**
* Method returning the last item
* @uses PackageNameWsdlClass::item()
* @uses PackageNameWsdlClass::length()
* @return mixed
*/
public function last()
{
return $this->item($this->length() - 1);
}
/**
* Method testing index in item
* @uses PackageNameWsdlClass::getInternArrayToIterateIsArray()
* @uses PackageNameWsdlClass::getInternArrayToIterate()
* @param int $_offset
* @return bool true|false
*/
public function offsetExists($_offset)
{
return ($this->getInternArrayToIterateIsArray() && array_key_exists($_offset,$this->getInternArrayToIterate()));
}
/**
* Method returning the item at "index" value
* @uses PackageNameWsdlClass::offsetExists()
* @param int $_offset
* @return mixed
*/
public function offsetGet($_offset)
{
return $this->offsetExists($_offset)?$this->internArrayToIterate[$_offset]:null;
}
/**
* Method useless but necessarly overridden, can't set
* @param mixed $_offset
* @param mixed $_value
* @return null
*/
public function offsetSet($_offset,$_value)
{
return null;
}
/**
* Method useless but necessarly overridden, can't unset
* @param mixed $_offset
* @return null
*/
public function offsetUnset($_offset)
{
return null;
}
/**
* Method returning current result from Soap call
* @return mixed
*/
public function getResult()
{
return $this->result;
}
/**
* Method setting current result from Soap call
* @param mixed $_result
* @return mixed
*/
protected function setResult($_result)
{
return ($this->result = $_result);
}
/**
* Method returning last errors occured during the calls
* @return array
*/
public function getLastError()
{
return $this->lastError;
}
/**
* Method setting last errors occured during the calls
* @param array $_lastError
* @return array
*/
private function setLastError($_lastError)
{
return ($this->lastError = $_lastError);
}
/**
* Method saving the last error returned by the SoapClient
* @param string $_methoName the method called when the error occurred
* @param SoapFault $_soapFault l'objet de l'erreur
* @return bool true|false
*/
protected function saveLastError($_methoName,SoapFault $_soapFault)
{
return ($this->lastError[$_methoName] = $_soapFault);
}
/**
* Method getting the last error for a certain method
* @param string $_methoName method name to get error from
* @return SoapFault|null
*/
public function getLastErrorForMethod($_methoName)
{
return (is_array($this->lastError) && array_key_exists($_methoName,$this->lastError))?$this->lastError[$_methoName]:null;
}
/**
* Method returning intern array to iterate trough
* @return array
*/
public function getInternArrayToIterate()
{
return $this->internArrayToIterate;
}
/**
* Method setting intern array to iterate trough
* @param array $_internArrayToIterate
* @return array
*/
public function setInternArrayToIterate($_internArrayToIterate)
{
return ($this->internArrayToIterate = $_internArrayToIterate);
}
/**
* Method returnint intern array index when iterating trough
* @return int
*/
public function getInternArrayToIterateOffset()
{
return $this->internArrayToIterateOffset;
}
/**
* Method initiating internArrayToIterate
* @uses PackageNameWsdlClass::setInternArrayToIterate()
* @uses PackageNameWsdlClass::setInternArrayToIterateOffset()
* @uses PackageNameWsdlClass::setInternArrayToIterateIsArray()
* @uses PackageNameWsdlClass::getAttributeName()
* @uses PackageNameWsdlClass::initInternArrayToIterate()
* @uses PackageNameWsdlClass::__toString()
* @param array $_array the array to iterate trough
* @param bool $_internCall indicates that methods is calling itself
* @return void
*/
public function initInternArrayToIterate($_array = array(),$_internCall = false)
{
if(stripos($this->__toString(),'array') !== false)
{
if(is_array($_array) && count($_array))
{
$this->setInternArrayToIterate($_array);
$this->setInternArrayToIterateOffset(0);
$this->setInternArrayToIterateIsArray(true);
}
elseif(!$_internCall && $this->getAttributeName() != '' && property_exists($this->__toString(),$this->getAttributeName()))
$this->initInternArrayToIterate($this->_get($this->getAttributeName()),true);
}
}
/**
* Method setting intern array offset when iterating trough
* @param int $_internArrayToIterateOffset
* @return int
*/
public function setInternArrayToIterateOffset($_internArrayToIterateOffset)
{
return ($this->internArrayToIterateOffset = $_internArrayToIterateOffset);
}
/**
* Method returning true if intern array is an actual array
* @return bool true|false
*/
public function getInternArrayToIterateIsArray()
{
return $this->internArrayToIterateIsArray;
}
/**
* Method setting if intern array is an actual array
* @param bool $_internArrayToIterateIsArray
* @return bool true|false
*/
public function setInternArrayToIterateIsArray($_internArrayToIterateIsArray = false)
{
return ($this->internArrayToIterateIsArray = $_internArrayToIterateIsArray);
}
/**
* Generic method setting value
* @param string $_name property name to set
* @param mixed $_value property value to use
* @return bool
*/
public function _set($_name,$_value)
{
$setMethod = 'set' . ucfirst($_name);
if(method_exists($this,$setMethod))
{
$this->$setMethod($_value);
return true;
}
else
return false;
}
/**
* Generic method getting value
* @param string $_name property name to get
* @return mixed
*/
public function _get($_name)
{
$getMethod = 'get' . ucfirst($_name);
if(method_exists($this,$getMethod))
return $this->$getMethod();
else
return false;
}
/**
* Method returning alone attribute name when class is *array* type
* @return string
*/
public function getAttributeName()
{
return '';
}
/**
* Generic method telling if current value is valid according to the attribute setted with the current value
* @param mixed $_value the value to test
* @return bool true|false
*/
public static function valueIsValid($_value)
{
return true;
}
/**
* Method returning actual class name
* @return string __CLASS__
*/
public function __toString()
{
return __CLASS__;
}
}
?>