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 $GLOBALS['_transient']['static']['nusoap_base']->globalDebugLevel = 9;
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 class nusoap_base {
00063
00064
00065
00066
00067
00068
00069 var $title = 'NuSOAP';
00070
00071
00072
00073
00074
00075
00076 var $version = '0.7.2';
00077
00078
00079
00080
00081
00082
00083 var $revision = '$Revision: 2663 $';
00084
00085
00086
00087
00088
00089
00090 var $error_str = '';
00091
00092
00093
00094
00095
00096
00097 var $debug_str = '';
00098
00099
00100
00101
00102
00103
00104
00105 var $charencoding = true;
00106
00107
00108
00109
00110
00111
00112 var $debugLevel;
00113
00114
00115
00116
00117
00118
00119
00120 var $XMLSchemaVersion = 'http:
00121
00122
00123
00124
00125
00126
00127
00128 var $soap_defencoding = 'ISO-8859-1';
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 var $namespaces = array(
00140 'SOAP-ENV' => 'http:
00141 'xsd' => 'http:
00142 'xsi' => 'http:
00143 'SOAP-ENC' => 'http:
00144 );
00145
00146
00147
00148
00149
00150
00151
00152 var $usedNamespaces = array();
00153
00154
00155
00156
00157
00158
00159
00160
00161 var $typemap = array(
00162 'http:
00163 'string'=>'string','boolean'=>'boolean','float'=>'double','double'=>'double','decimal'=>'double',
00164 'duration'=>'','dateTime'=>'string','time'=>'string','date'=>'string','gYearMonth'=>'',
00165 'gYear'=>'','gMonthDay'=>'','gDay'=>'','gMonth'=>'','hexBinary'=>'string','base64Binary'=>'string',
00166
00167 'anyType'=>'string','anySimpleType'=>'string',
00168
00169 'normalizedString'=>'string','token'=>'string','language'=>'','NMTOKEN'=>'','NMTOKENS'=>'','Name'=>'','NCName'=>'','ID'=>'',
00170 'IDREF'=>'','IDREFS'=>'','ENTITY'=>'','ENTITIES'=>'','integer'=>'integer','nonPositiveInteger'=>'integer',
00171 'negativeInteger'=>'integer','long'=>'integer','int'=>'integer','short'=>'integer','byte'=>'integer','nonNegativeInteger'=>'integer',
00172 'unsignedLong'=>'','unsignedInt'=>'','unsignedShort'=>'','unsignedByte'=>'','positiveInteger'=>''),
00173 'http:
00174 'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double',
00175 'float'=>'double','dateTime'=>'string',
00176 'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'),
00177 'http:
00178 'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double',
00179 'float'=>'double','dateTime'=>'string',
00180 'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'),
00181 'http:
00182 'http:
00183 'http:
00184 );
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194 var $xmlEntities = array('quot' => '"','amp' => '&',
00195 'lt' => '<','gt' => '>','apos' => "'");
00196
00197
00198
00199
00200
00201
00202 function nusoap_base() {
00203 $this->debugLevel = $GLOBALS['_transient']['static']['nusoap_base']->globalDebugLevel;
00204 }
00205
00206
00207
00208
00209
00210
00211
00212 function getGlobalDebugLevel() {
00213 return $GLOBALS['_transient']['static']['nusoap_base']->globalDebugLevel;
00214 }
00215
00216
00217
00218
00219
00220
00221
00222 function setGlobalDebugLevel($level) {
00223 $GLOBALS['_transient']['static']['nusoap_base']->globalDebugLevel = $level;
00224 }
00225
00226
00227
00228
00229
00230
00231
00232 function getDebugLevel() {
00233 return $this->debugLevel;
00234 }
00235
00236
00237
00238
00239
00240
00241
00242 function setDebugLevel($level) {
00243 $this->debugLevel = $level;
00244 }
00245
00246
00247
00248
00249
00250
00251
00252 function debug($string){
00253 if ($this->debugLevel > 0) {
00254 $this->appendDebug($this->getmicrotime().' '.get_class($this).": $string\n");
00255 }
00256 }
00257
00258
00259
00260
00261
00262
00263
00264 function appendDebug($string){
00265 if ($this->debugLevel > 0) {
00266
00267
00268 $this->debug_str .= $string;
00269 }
00270 }
00271
00272
00273
00274
00275
00276
00277 function clearDebug() {
00278
00279
00280 $this->debug_str = '';
00281 }
00282
00283
00284
00285
00286
00287
00288
00289 function &getDebug() {
00290
00291
00292 return $this->debug_str;
00293 }
00294
00295
00296
00297
00298
00299
00300
00301
00302 function &getDebugAsXMLComment() {
00303
00304
00305 while (strpos($this->debug_str, '--')) {
00306 $this->debug_str = str_replace('--', '- -', $this->debug_str);
00307 }
00308 return "<!--\n" . $this->debug_str . "\n-->";
00309 }
00310
00311
00312
00313
00314
00315
00316
00317 function expandEntities($val) {
00318 if ($this->charencoding) {
00319 $val = str_replace('&', '&', $val);
00320 $val = str_replace("'", ''', $val);
00321 $val = str_replace('"', '"', $val);
00322 $val = str_replace('<', '<', $val);
00323 $val = str_replace('>', '>', $val);
00324 }
00325 return $val;
00326 }
00327
00328
00329
00330
00331
00332
00333
00334 function getError(){
00335 if($this->error_str != ''){
00336 return $this->error_str;
00337 }
00338 return false;
00339 }
00340
00341
00342
00343
00344
00345
00346
00347 function setError($str){
00348 $this->error_str = $str;
00349 }
00350
00351
00352
00353
00354
00355
00356
00357
00358 function isArraySimpleOrStruct($val) {
00359 $keyList = array_keys($val);
00360 foreach ($keyList as $keyListValue) {
00361 if (!is_int($keyListValue)) {
00362 return 'arrayStruct';
00363 }
00364 }
00365 return 'arraySimple';
00366 }
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382 function serialize_val($val,$name=false,$type=false,$name_ns=false,$type_ns=false,$attributes=false,$use='encoded'){
00383 $this->debug("in serialize_val: name=$name, type=$type, name_ns=$name_ns, type_ns=$type_ns, use=$use");
00384 $this->appendDebug('value=' . $this->varDump($val));
00385 $this->appendDebug('attributes=' . $this->varDump($attributes));
00386
00387 if(is_object($val) && get_class($val) == 'soapval'){
00388 return $val->serialize($use);
00389 }
00390
00391 if (is_numeric($name)) {
00392 $name = '__numeric_' . $name;
00393 } elseif (! $name) {
00394 $name = 'noname';
00395 }
00396
00397 $xmlns = '';
00398 if($name_ns){
00399 $prefix = 'nu'.rand(1000,9999);
00400 $name = $prefix.':'.$name;
00401 $xmlns .= " xmlns:$prefix=\"$name_ns\"";
00402 }
00403
00404 if($type_ns != '' && $type_ns == $this->namespaces['xsd']){
00405
00406
00407 $type_prefix = 'xsd';
00408 } elseif($type_ns){
00409 $type_prefix = 'ns'.rand(1000,9999);
00410 $xmlns .= " xmlns:$type_prefix=\"$type_ns\"";
00411 }
00412
00413 $atts = '';
00414 if($attributes){
00415 foreach($attributes as $k => $v){
00416 $atts .= " $k=\"".$this->expandEntities($v).'"';
00417 }
00418 }
00419
00420 if (is_null($val)) {
00421 if ($use == 'literal') {
00422
00423 return "<$name$xmlns $atts/>";
00424 } else {
00425 if (isset($type) && isset($type_prefix)) {
00426 $type_str = " xsi:type=\"$type_prefix:$type\"";
00427 } else {
00428 $type_str = '';
00429 }
00430 return "<$name$xmlns$type_str $atts xsi:nil=\"true\"/>";
00431 }
00432 }
00433
00434 if($type != '' && isset($this->typemap[$this->XMLSchemaVersion][$type])){
00435 if (is_bool($val)) {
00436 if ($type == 'boolean') {
00437 $val = $val ? 'true' : 'false';
00438 } elseif (! $val) {
00439 $val = 0;
00440 }
00441 } else if (is_string($val)) {
00442 $val = $this->expandEntities($val);
00443 }
00444 if ($use == 'literal') {
00445 return "<$name$xmlns $atts>$val</$name>";
00446 } else {
00447 return "<$name$xmlns $atts xsi:type=\"xsd:$type\">$val</$name>";
00448 }
00449 }
00450
00451 $xml = '';
00452 switch(true) {
00453 case (is_bool($val) || $type == 'boolean'):
00454 if ($type == 'boolean') {
00455 $val = $val ? 'true' : 'false';
00456 } elseif (! $val) {
00457 $val = 0;
00458 }
00459 if ($use == 'literal') {
00460 $xml .= "<$name$xmlns $atts>$val</$name>";
00461 } else {
00462 $xml .= "<$name$xmlns xsi:type=\"xsd:boolean\"$atts>$val</$name>";
00463 }
00464 break;
00465 case (is_int($val) || is_long($val) || $type == 'int'):
00466 if ($use == 'literal') {
00467 $xml .= "<$name$xmlns $atts>$val</$name>";
00468 } else {
00469 $xml .= "<$name$xmlns xsi:type=\"xsd:int\"$atts>$val</$name>";
00470 }
00471 break;
00472 case (is_float($val)|| is_double($val) || $type == 'float'):
00473 if ($use == 'literal') {
00474 $xml .= "<$name$xmlns $atts>$val</$name>";
00475 } else {
00476 $xml .= "<$name$xmlns xsi:type=\"xsd:float\"$atts>$val</$name>";
00477 }
00478 break;
00479 case (is_string($val) || $type == 'string'):
00480 $val = $this->expandEntities($val);
00481 if ($use == 'literal') {
00482 $xml .= "<$name$xmlns $atts>$val</$name>";
00483 } else {
00484 $xml .= "<$name$xmlns xsi:type=\"xsd:string\"$atts>$val</$name>";
00485 }
00486 break;
00487 case is_object($val):
00488 if (! $name) {
00489 $name = get_class($val);
00490 $this->debug("In serialize_val, used class name $name as element name");
00491 } else {
00492 $this->debug("In serialize_val, do not override name $name for element name for class " . get_class($val));
00493 }
00494 foreach(get_object_vars($val) as $k => $v){
00495 $pXml = isset($pXml) ? $pXml.$this->serialize_val($v,$k,false,false,false,false,$use) : $this->serialize_val($v,$k,false,false,false,false,$use);
00496 }
00497 $xml .= '<'.$name.'>'.$pXml.'</'.$name.'>';
00498 break;
00499 break;
00500 case (is_array($val) || $type):
00501
00502 $valueType = $this->isArraySimpleOrStruct($val);
00503 if($valueType=='arraySimple' || ereg('^ArrayOf',$type)){
00504 $i = 0;
00505 if(is_array($val) && count($val)> 0){
00506 foreach($val as $v){
00507 if(is_object($v) && get_class($v) == 'soapval'){
00508 $tt_ns = $v->type_ns;
00509 $tt = $v->type;
00510 } elseif (is_array($v)) {
00511 $tt = $this->isArraySimpleOrStruct($v);
00512 } else {
00513 $tt = gettype($v);
00514 }
00515 $array_types[$tt] = 1;
00516
00517 $xml .= $this->serialize_val($v,'item',false,false,false,false,$use);
00518 ++$i;
00519 }
00520 if(count($array_types) > 1){
00521 $array_typename = 'xsd:anyType';
00522 } elseif(isset($tt) && isset($this->typemap[$this->XMLSchemaVersion][$tt])) {
00523 if ($tt == 'integer') {
00524 $tt = 'int';
00525 }
00526 $array_typename = 'xsd:'.$tt;
00527 } elseif(isset($tt) && $tt == 'arraySimple'){
00528 $array_typename = 'SOAP-ENC:Array';
00529 } elseif(isset($tt) && $tt == 'arrayStruct'){
00530 $array_typename = 'unnamed_struct_use_soapval';
00531 } else {
00532
00533 if ($tt_ns != '' && $tt_ns == $this->namespaces['xsd']){
00534 $array_typename = 'xsd:' . $tt;
00535 } elseif ($tt_ns) {
00536 $tt_prefix = 'ns' . rand(1000, 9999);
00537 $array_typename = "$tt_prefix:$tt";
00538 $xmlns .= " xmlns:$tt_prefix=\"$tt_ns\"";
00539 } else {
00540 $array_typename = $tt;
00541 }
00542 }
00543 $array_type = $i;
00544 if ($use == 'literal') {
00545 $type_str = '';
00546 } else if (isset($type) && isset($type_prefix)) {
00547 $type_str = " xsi:type=\"$type_prefix:$type\"";
00548 } else {
00549 $type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"".$array_typename."[$array_type]\"";
00550 }
00551
00552 } else {
00553 if ($use == 'literal') {
00554 $type_str = '';
00555 } else if (isset($type) && isset($type_prefix)) {
00556 $type_str = " xsi:type=\"$type_prefix:$type\"";
00557 } else {
00558 $type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"xsd:anyType[0]\"";
00559 }
00560 }
00561
00562 $xml = "<$name$xmlns$type_str$atts>".$xml."</$name>";
00563 } else {
00564
00565 if(isset($type) && isset($type_prefix)){
00566 $type_str = " xsi:type=\"$type_prefix:$type\"";
00567 } else {
00568 $type_str = '';
00569 }
00570 if ($use == 'literal') {
00571 $xml .= "<$name$xmlns $atts>";
00572 } else {
00573 $xml .= "<$name$xmlns$type_str$atts>";
00574 }
00575 foreach($val as $k => $v){
00576
00577 if ($type == 'Map' && $type_ns == 'http:
00578 $xml .= '<item>';
00579 $xml .= $this->serialize_val($k,'key',false,false,false,false,$use);
00580 $xml .= $this->serialize_val($v,'value',false,false,false,false,$use);
00581 $xml .= '</item>';
00582 } else {
00583 $xml .= $this->serialize_val($v,$k,false,false,false,false,$use);
00584 }
00585 }
00586 $xml .= "</$name>";
00587 }
00588 break;
00589 default:
00590 $xml .= 'not detected, got '.gettype($val).' for '.$val;
00591 break;
00592 }
00593 return $xml;
00594 }
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608 function serializeEnvelope($body,$headers=false,$namespaces=array(),$style='rpc',$use='encoded',$encodingStyle='http:
00609
00610
00611
00612
00613 $this->debug("In serializeEnvelope length=" . strlen($body) . " body (max 1000 characters)=" . substr($body, 0, 1000) . " style=$style use=$use encodingStyle=$encodingStyle");
00614 $this->debug("headers:");
00615 $this->appendDebug($this->varDump($headers));
00616 $this->debug("namespaces:");
00617 $this->appendDebug($this->varDump($namespaces));
00618
00619
00620 $ns_string = '';
00621 foreach(array_merge($this->namespaces,$namespaces) as $k => $v){
00622 $ns_string .= " xmlns:$k=\"$v\"";
00623 }
00624 if($encodingStyle) {
00625 $ns_string = " SOAP-ENV:encodingStyle=\"$encodingStyle\"$ns_string";
00626 }
00627
00628
00629 if($headers){
00630 if (is_array($headers)) {
00631 $xml = '';
00632 foreach ($headers as $header) {
00633 $xml .= $this->serialize_val($header, false, false, false, false, false, $use);
00634 }
00635 $headers = $xml;
00636 $this->debug("In serializeEnvelope, serialzied array of headers to $headers");
00637 }
00638 $headers = "<SOAP-ENV:Header>".$headers."</SOAP-ENV:Header>";
00639 }
00640
00641 return
00642 '<?xml version="1.0" encoding="'.$this->soap_defencoding .'"?'.">".
00643 '<SOAP-ENV:Envelope'.$ns_string.">".
00644 $headers.
00645 "<SOAP-ENV:Body>".
00646 $body.
00647 "</SOAP-ENV:Body>".
00648 "</SOAP-ENV:Envelope>";
00649 }
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659 function formatDump($str){
00660 $str = htmlspecialchars($str);
00661 return nl2br($str);
00662 }
00663
00664
00665
00666
00667
00668
00669
00670
00671 function contractQname($qname){
00672
00673
00674 if (strrpos($qname, ':')) {
00675
00676 $name = substr($qname, strrpos($qname, ':') + 1);
00677
00678 $ns = substr($qname, 0, strrpos($qname, ':'));
00679 $p = $this->getPrefixFromNamespace($ns);
00680 if ($p) {
00681 return $p . ':' . $name;
00682 }
00683 return $qname;
00684 } else {
00685 return $qname;
00686 }
00687 }
00688
00689
00690
00691
00692
00693
00694
00695
00696 function expandQname($qname){
00697
00698 if(strpos($qname,':') && !ereg('^http:
00699
00700 $name = substr(strstr($qname,':'),1);
00701
00702 $prefix = substr($qname,0,strpos($qname,':'));
00703 if(isset($this->namespaces[$prefix])){
00704 return $this->namespaces[$prefix].':'.$name;
00705 } else {
00706 return $qname;
00707 }
00708 } else {
00709 return $qname;
00710 }
00711 }
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721 function getLocalPart($str){
00722 if($sstr = strrchr($str,':')){
00723
00724 return substr( $sstr, 1 );
00725 } else {
00726 return $str;
00727 }
00728 }
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738 function getPrefix($str){
00739 if($pos = strrpos($str,':')){
00740
00741 return substr($str,0,$pos);
00742 }
00743 return false;
00744 }
00745
00746
00747
00748
00749
00750
00751
00752
00753 function getNamespaceFromPrefix($prefix){
00754 if (isset($this->namespaces[$prefix])) {
00755 return $this->namespaces[$prefix];
00756 }
00757
00758 return false;
00759 }
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769 function getPrefixFromNamespace($ns) {
00770 foreach ($this->namespaces as $p => $n) {
00771 if ($ns == $n || $ns == $p) {
00772 $this->usedNamespaces[$p] = $n;
00773 return $p;
00774 }
00775 }
00776 return false;
00777 }
00778
00779
00780
00781
00782
00783
00784
00785 function getmicrotime() {
00786 if (function_exists('gettimeofday')) {
00787 $tod = gettimeofday();
00788 $sec = $tod['sec'];
00789 $usec = $tod['usec'];
00790 } else {
00791 $sec = time();
00792 $usec = 0;
00793 }
00794 return strftime('%Y-%m-%d %H:%M:%S', $sec) . '.' . sprintf('%06d', $usec);
00795 }
00796
00797
00798
00799
00800
00801
00802
00803
00804 function varDump($data) {
00805 ob_start();
00806 var_dump($data);
00807 $ret_val = ob_get_contents();
00808 ob_end_clean();
00809 return $ret_val;
00810 }
00811 }
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823 function timestamp_to_iso8601($timestamp,$utc=true){
00824 $datestr = date('Y-m-d\TH:i:sO',$timestamp);
00825 if($utc){
00826 $eregStr =
00827 '([0-9]{4})-'.
00828 '([0-9]{2})-'.
00829 '([0-9]{2})'.
00830 'T'.
00831 '([0-9]{2}):'.
00832 '([0-9]{2}):'.
00833 '([0-9]{2})(\.[0-9]*)?'.
00834 '(Z|[+\-][0-9]{2}:?[0-9]{2})?';
00835
00836 if(ereg($eregStr,$datestr,$regs)){
00837 return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ',$regs[1],$regs[2],$regs[3],$regs[4],$regs[5],$regs[6]);
00838 }
00839 return false;
00840 } else {
00841 return $datestr;
00842 }
00843 }
00844
00845
00846
00847
00848
00849
00850
00851 function iso8601_to_timestamp($datestr){
00852 $eregStr =
00853 '([0-9]{4})-'.
00854 '([0-9]{2})-'.
00855 '([0-9]{2})'.
00856 'T'.
00857 '([0-9]{2}):'.
00858 '([0-9]{2}):'.
00859 '([0-9]{2})(\.[0-9]+)?'.
00860 '(Z|[+\-][0-9]{2}:?[0-9]{2})?';
00861 if(ereg($eregStr,$datestr,$regs)){
00862
00863 if($regs[8] != 'Z'){
00864 $op = substr($regs[8],0,1);
00865 $h = substr($regs[8],1,2);
00866 $m = substr($regs[8],strlen($regs[8])-2,2);
00867 if($op == '-'){
00868 $regs[4] = $regs[4] + $h;
00869 $regs[5] = $regs[5] + $m;
00870 } elseif($op == '+'){
00871 $regs[4] = $regs[4] - $h;
00872 $regs[5] = $regs[5] - $m;
00873 }
00874 }
00875 return strtotime("$regs[1]-$regs[2]-$regs[3] $regs[4]:$regs[5]:$regs[6]Z");
00876 } else {
00877 return false;
00878 }
00879 }
00880
00881
00882
00883
00884
00885
00886
00887
00888 function usleepWindows($usec)
00889 {
00890 $start = gettimeofday();
00891
00892 do
00893 {
00894 $stop = gettimeofday();
00895 $timePassed = 1000000 * ($stop['sec'] - $start['sec'])
00896 + $stop['usec'] - $start['usec'];
00897 }
00898 while ($timePassed < $usec);
00899 }
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911 class soap_fault extends nusoap_base {
00912
00913
00914
00915
00916
00917 var $faultcode;
00918
00919
00920
00921
00922
00923 var $faultactor;
00924
00925
00926
00927
00928
00929 var $faultstring;
00930
00931
00932
00933
00934
00935 var $faultdetail;
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945 function soap_fault($faultcode,$faultactor='',$faultstring='',$faultdetail=''){
00946 parent::nusoap_base();
00947 $this->faultcode = $faultcode;
00948 $this->faultactor = $faultactor;
00949 $this->faultstring = $faultstring;
00950 $this->faultdetail = $faultdetail;
00951 }
00952
00953
00954
00955
00956
00957
00958
00959 function serialize(){
00960 $ns_string = '';
00961 foreach($this->namespaces as $k => $v){
00962 $ns_string .= "\n xmlns:$k=\"$v\"";
00963 }
00964 $return_msg =
00965 '<?xml version="1.0" encoding="'.$this->soap_defencoding.'"?>'.
00966 '<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"'.$ns_string.">\n".
00967 '<SOAP-ENV:Body>'.
00968 '<SOAP-ENV:Fault>'.
00969 $this->serialize_val($this->faultcode, 'faultcode').
00970 $this->serialize_val($this->faultactor, 'faultactor').
00971 $this->serialize_val($this->faultstring, 'faultstring').
00972 $this->serialize_val($this->faultdetail, 'detail').
00973 '</SOAP-ENV:Fault>'.
00974 '</SOAP-ENV:Body>'.
00975 '</SOAP-ENV:Envelope>';
00976 return $return_msg;
00977 }
00978 }
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993 class XMLSchema extends nusoap_base {
00994
00995
00996 var $schema = '';
00997 var $xml = '';
00998
00999 var $enclosingNamespaces;
01000
01001 var $schemaInfo = array();
01002 var $schemaTargetNamespace = '';
01003
01004 var $attributes = array();
01005 var $complexTypes = array();
01006 var $complexTypeStack = array();
01007 var $currentComplexType = null;
01008 var $elements = array();
01009 var $elementStack = array();
01010 var $currentElement = null;
01011 var $simpleTypes = array();
01012 var $simpleTypeStack = array();
01013 var $currentSimpleType = null;
01014
01015 var $imports = array();
01016
01017 var $parser;
01018 var $position = 0;
01019 var $depth = 0;
01020 var $depth_array = array();
01021 var $message = array();
01022 var $defaultNamespace = array();
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032 function XMLSchema($schema='',$xml='',$namespaces=array()){
01033 parent::nusoap_base();
01034 $this->debug('xmlschema class instantiated, inside constructor');
01035
01036 $this->schema = $schema;
01037 $this->xml = $xml;
01038
01039
01040 $this->enclosingNamespaces = $namespaces;
01041 $this->namespaces = array_merge($this->namespaces, $namespaces);
01042
01043
01044 if($schema != ''){
01045 $this->debug('initial schema file: '.$schema);
01046 $this->parseFile($schema, 'schema');
01047 }
01048
01049
01050 if($xml != ''){
01051 $this->debug('initial xml file: '.$xml);
01052 $this->parseFile($xml, 'xml');
01053 }
01054
01055 }
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065 function parseFile($xml,$type){
01066
01067 if($xml != ""){
01068 $xmlStr = @join("",@file($xml));
01069 if($xmlStr == ""){
01070 $msg = 'Error reading XML from '.$xml;
01071 $this->setError($msg);
01072 $this->debug($msg);
01073 return false;
01074 } else {
01075 $this->debug("parsing $xml");
01076 $this->parseString($xmlStr,$type);
01077 $this->debug("done parsing $xml");
01078 return true;
01079 }
01080 }
01081 return false;
01082 }
01083
01084
01085
01086
01087
01088
01089
01090
01091 function parseString($xml,$type){
01092
01093 if($xml != ""){
01094
01095
01096 $this->parser = xml_parser_create();
01097
01098 xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
01099
01100
01101 xml_set_object($this->parser, $this);
01102
01103
01104 if($type == "schema"){
01105 xml_set_element_handler($this->parser, 'schemaStartElement','schemaEndElement');
01106 xml_set_character_data_handler($this->parser,'schemaCharacterData');
01107 } elseif($type == "xml"){
01108 xml_set_element_handler($this->parser, 'xmlStartElement','xmlEndElement');
01109 xml_set_character_data_handler($this->parser,'xmlCharacterData');
01110 }
01111
01112
01113 if(!xml_parse($this->parser,$xml,true)){
01114
01115 $errstr = sprintf('XML error parsing XML schema on line %d: %s',
01116 xml_get_current_line_number($this->parser),
01117 xml_error_string(xml_get_error_code($this->parser))
01118 );
01119 $this->debug($errstr);
01120 $this->debug("XML payload:\n" . $xml);
01121 $this->setError($errstr);
01122 }
01123
01124 xml_parser_free($this->parser);
01125 } else{
01126 $this->debug('no xml passed to parseString()!!');
01127 $this->setError('no xml passed to parseString()!!');
01128 }
01129 }
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139 function schemaStartElement($parser, $name, $attrs) {
01140
01141
01142 $pos = $this->position++;
01143 $depth = $this->depth++;
01144
01145 $this->depth_array[$depth] = $pos;
01146 $this->message[$pos] = array('cdata' => '');
01147 if ($depth > 0) {
01148 $this->defaultNamespace[$pos] = $this->defaultNamespace[$this->depth_array[$depth - 1]];
01149 } else {
01150 $this->defaultNamespace[$pos] = false;
01151 }
01152
01153
01154 if($prefix = $this->getPrefix($name)){
01155
01156 $name = $this->getLocalPart($name);
01157 } else {
01158 $prefix = '';
01159 }
01160
01161
01162 if(count($attrs) > 0){
01163 foreach($attrs as $k => $v){
01164
01165 if(ereg("^xmlns",$k)){
01166
01167
01168 if($ns_prefix = substr(strrchr($k,':'),1)){
01169
01170 $this->namespaces[$ns_prefix] = $v;
01171 } else {
01172 $this->defaultNamespace[$pos] = $v;
01173 if (! $this->getPrefixFromNamespace($v)) {
01174 $this->namespaces['ns'.(count($this->namespaces)+1)] = $v;
01175 }
01176 }
01177 if($v == 'http:
01178 $this->XMLSchemaVersion = $v;
01179 $this->namespaces['xsi'] = $v.'-instance';
01180 }
01181 }
01182 }
01183 foreach($attrs as $k => $v){
01184
01185 $k = strpos($k,':') ? $this->expandQname($k) : $k;
01186 $v = strpos($v,':') ? $this->expandQname($v) : $v;
01187 $eAttrs[$k] = $v;
01188 }
01189 $attrs = $eAttrs;
01190 } else {
01191 $attrs = array();
01192 }
01193
01194 switch($name){
01195 case 'all':
01196 case 'choice':
01197 case 'group':
01198 case 'sequence':
01199
01200 $this->complexTypes[$this->currentComplexType]['compositor'] = $name;
01201
01202